繁体   English   中英

属性值是在集合上URI编码的

[英]Attribute value is URI encoded on set

我想设置一个attribute使用DOM元素的element["attribute"]但该值是URI encoded 例如,如果值为q=test&r=123&s=456 ,然后将其附加到DOM中,则该值将变为q=test&r=123&s=456

现在,查看RENDERED源 ,或使用Firebug 复制脚本标签的HTML ...

请复制以下代码,将其粘贴到新的HTML文件中,以进行有价值的调查。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <a href="javascript: injectTag();">Inject Tag</a>
    <div id="status"></div>
    <script>
        var injectTag = function () {
            var scriptTag = document.createElement("script");
            scriptTag["src"] = "http://www.google.com/search?q=US+Geological+Survey&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a";
            scriptTag["type"] = "text/javascript";

            var head = document.getElementsByTagName("head")[0];
            head.appendChild(scriptTag);
            document.getElementById("status").innerHTML = "Now, view <b>RENDERED source</b>, or <b>Copy HTML</b> of the script tag using Firebug...";
        }
    </script>
</body>
</html>

衷心的感谢,
慕尼姆

您所看到的正是应该发生的情况。

不过,该值不是URI编码的。 它是HTML转义的。

HTML页面中的所有数据(数据是:属性值和文本)都必须经过HTML转义(在源代码中, &变为&amp;<变为&lt;依此类推)。 如果您忘记这样做,大多数浏览器都会原谅,但这仍然是错误的。

如果您动态添加数据,则DOM仅遵循该规则,然后HTML为您转义数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM