惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - life++

multer /busboy 上传文件无法完成回调问题 linux系统上搭建egret构建环境(针对5.3.x 版以上) android studio 2.0 Gradle HttpProxy 设置 javascript的 parseInt 曾经的“陷井”在IE10上不见了,但还是得注意! 无法将类型为“xxxx”的对象强制转换为类型“Microsoft.SharePoint.WebPartPages.WebPart”。 ajax 12301 原因小结 被人忽悠完成的56.com我秀聊天室群发软件 WebDav基于Exchange2003开发邮件收发系统 fiddler 调试 WebDav 引起400错误处理 [笔记]443端口没开放让svn https连接不上 ora10ginstant 精简客户端遇到 system.data.oracleclient 需要 oracle 客户端软件8.1.7 或更高版本 手动调用__doPostBack('xx','') 在IE6, 下留意 javascript:void(0);问题。 让relative容器里的元素的z-index高于body下的遮照层 [原]SWFUpload 在IE9下不显示问题及IE9中模态窗下flash文件选择问题的处理 JQuery-easyui accordion 滚动条在IE6下“丢失”的处理 asp.net Ajax 页中使用jquery-easyui的显示问题处理 equal 与 == 自问自答 胡乱写个 List string 类型排序。
HTML-JS中的单双引混合处理原则
life++ · 2011-09-13 · via 博客园 - life++

Web 开发时常会遇到 链接中调用JS操作,如:

<a href="#" onclick="showName('donhwa')">查看名字</a>

这里的名字  donhwa ,偶尔会带有 单引,或双引,或兼有之。 这时,又要如何调整才不会暴脚本感叹号呢? 也许你我都经常遇到,偶尔调整一阵可以了就这样过了,没有总结下来。

下面是整理了一下的结果,记录一下。

https://files.cnblogs.com/donhwa/testQuote.rar

<html>
<head>
    <title>HTML-JS中的单双引混合处理-[by www.cnblogs.com/donhwa]</title>
    <style type="text/css">
        body
        {
            font:normal 14px/20px 微软雅黑;
            color:#506;
            line-height: 200%;
        }
        dd{padding:4px 8px;}
        p{padding:0 10px;}
        a{display:block;}
        em{color:Red;display:block;}
    </style>
</head>
<body>
    <dl>
        <dt>HTML-JS中的单双引混合处理-[by www.cnblogs.com/donhwa]</dt>
        <dd>
            <strong>情形一:无符号内容</strong>
            <p>
                <a href="#" onclick="alert('0')">Html双引,JS单引</a>
                <a href="#" onclick='alert("0")'>Html单引,JS双引</a>
            </p>
        </dd>
        <dd>
            <strong>情形二:含单引及双引内容</strong><br />
            <p>
            <a href="#" onclick="alert('  \' " ')">Html双引,JS单引包装</a>
            <em>单引转义,双引编码</em>
            <a href="#" onclick='alert("  '\"   ")'>Html单引,JS双引包装</a>
            <em>双引转义,单引编码</em>
            </p>
        </dd>
        <dd>
            <strong>情形三:Html 无引</strong><br />
            <a href="#" onclick=alert('abcdef')>Html无引,内容无空格</a><em>尽量不要用无引方式</em>
            <a href="#" onclick=alert('ab cdef')>Html无引,内容中间空格</a><em>引发JS错误</em>
            <a href="#" onclick=alert(' abcdef ')>Html无引,内容左右空格</a><em>引发HTML错误</em>
        </dd>
        <dd>
        <h3>结论</h3>
        以JS的字符包装符号区分,用啥包装转义啥,另一个编码;
        </dd>
    </dl>
</body>
</html>