gpt4 book ai didi

javascript - 我可以在 <script> 标签内写一个 <script> 标签吗

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:35 25 4
gpt4 key购买 nike

这是我的代码。当屏幕宽度小于 1025 时,我试图停止运行外部 js 文件。

<script type="text/javascript">
var gdsize = 1025;
if(window.innerWidth>=gdsize) {

<script>
window.cookieconsent_options = {"message":"\"Geek Dashboard uses cookies to make sure you get the best experience on our website.\" -","dismiss":"It's OK","learnMore":"More Details Here","link":"http://www.geekdashboard.com/cookies/","theme":"dark-bottom"};
}
</script>


</script>

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/1.0.9/cookieconsent.min.js"></script>

最佳答案

<script type="text/x-jQuery-tmpl">
var gdsize = 1025;
if(window.innerWidth>=gdsize) {

<script type="text/javascript">
<!-- Some javascript here -->
window.cookieconsent_options = {"message":"\"Geek Dashboard uses cookies to make sure you get the best experience on our website.\" -","dismiss":"It's OK","learnMore":"More Details Here","link":"http://www.geekdashboard.com/cookies/","theme":"dark-bottom"};
}
{{html "</sc"+"ript>"}}
</script>

您可以使用 {{html "</sc"+"ript>"}}代替 </script>

解释[更新]:

当您使用 </script>带引号(文字)字符串内的 HTML 标记,该标记被视为结束标记而不是字符串的一部分。所以你不能直接使用 </script>脚本部分内的标记。

一种解决方法是转义 </script>标记和/或拆分 <script>标签:

var scriptEnd = "</scr" + "ipt>";
document.write(scriptEnd);

关于javascript - 我可以在 &lt;script&gt; 标签内写一个 &lt;script&gt; 标签吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33969544/

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