gpt4 book ai didi

javascript - javascript 属性值问题

转载 作者:行者123 更新时间:2023-11-30 07:23:42 25 4
gpt4 key购买 nike

<script type="text/javascript">
var randomnumber=Math.floor(Math.random()*10000);
var sr = 'http://www.example.com/example.js?rnd='+randomnumber;
document.write("<script type=\"text/javascript\" src=\"" + sr + "\" id-value-test=\"100\" > </script>");
</script>

id-value-test 获取未终止的字符串文字。有什么想法吗?

最佳答案

在进行 HTML 解析时,浏览器不会解析 JavaScript,因此它们会在第一个 </script> 处停止。他们找到的序列——即使它在字符串文字或 JavaScript 注释中。

要避免它,只需做任何事情来打断 </script>在你的字符串中,例如:

<script type="text/javascript">
var randomnumber=Math.floor(Math.random()*10000);
var sr = 'http://www.example.com/example.js?rnd='+randomnumber;
document.write("<script type=\"text/javascript\" src=\"" + sr + "\" id-value-test=\"100\" > <\/script>");
<!-- Change is here -----------------------------------------------------------------------------^ -->
</script>

<script type="text/javascript">
var randomnumber=Math.floor(Math.random()*10000);
var sr = 'http://www.example.com/example.js?rnd='+randomnumber;
document.write("<script type=\"text/javascript\" src=\"" + sr + "\" id-value-test=\"100\" > </" + "script>");
<!-- Change is here ----------------------------------------------------------------------------^ -->
</script>

关于javascript - javascript 属性值问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27066104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com