web front-end entry to combat: HTML-JS primer mix in the odd and even principles

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/wewfdf/article/details/102632065

Web developers often encounter links to call JS operations, such as:

<a href="#" onclick="showName('donhwa')">View name</a>

Here's name donhwa, occasionally with a single quote, or double quote, or a combination of. At this time, but also how to adjust the script will not storm the exclamation mark it? Maybe you and I often encounter occasionally adjust it so, after a while, it did not conclude.

The following is compiled a result, record it.


<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>

Guess you like

Origin blog.csdn.net/wewfdf/article/details/102632065