zoukankan      html  css  js  c++  java
  • HTMLJS中的单双引混合处理原则

    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>
    
  • 相关阅读:
    python note 30 断点续传
    python note 29 线程创建
    python note 28 socketserver
    python note 27 粘包
    python note 26 socket
    python note 25 约束
    Sed 用法
    python note 24 反射
    python note 23 组合
    python note 22 面向对象成员
  • 原文地址:https://www.cnblogs.com/donhwa/p/2174559.html
Copyright © 2011-2022 走看看