结束脚本标记和文档.write在Visual Studio中被标记

closing script tag and document.write gets flagged in Visual Studio

本文关键字:Visual Studio 文档 脚本 结束 write      更新时间:2023-09-26

环境:Visual Studio 2008 SP1, ASP。. NET和JavaScript

我想做一个快速的document.write测试,但只要我添加脚本标签Visual Studio编辑器不喜欢它。具体来说,是结束脚本标签?只要我输入结束的</script>标签

就会得到这些弯弯曲曲的线条
<html><head></head><body>
    <script type='text/javascript'>
      document.write('<html><head><script></script></head><body></body></html>');
    </script>
</body>
</html>

使用说明:

document.write('<html><head><script><'/script></head><body></body></html>');
Note the `'`, here ------------------^

另一个选择是分割字符串,这样它就不是一个精确的标签:

document.write('<html><head><script></sc' + 'ript></head><body></body></html>');

这里有一个参考,解释了为什么需要它,以及其他选项:

  • 为什么分割脚本<标记时写它与document.write()?>

不管怎样,你为什么要在<body>中写一整个文档?

我不熟悉Visual Studio,但我可以告诉你,你的HTML架构上有一些错误,你不应该重新插入<html><head><body>,如果它已经在HTML文档中,也尝试逃避斜杠:

<html><head></head><body>
    <script type='text/javascript'>
      document.write('<script>alert("hello");<'/script>');
    </script>
</body>
</html>

如果alert hello工作,那么你在良好的轨道