简体   繁体   English

关闭脚本标记和document.write在Visual Studio中被标记

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

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

I'm trying to do a quick document.write test but as soon as I add script tags Visual Studio editor doesn't like it. 我正在尝试进行快速的document.write测试,但是一旦添加脚本标签,Visual Studio编辑器就不喜欢它。 Specifically, the closing script tag? 具体来说,关闭脚本标签? I get those squiggly lines as soon as I enter the closing </script> tag 输入结束</script>标记后,我就会得到那些弯曲的线条

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

Use: 采用:

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

Another option is to split the string, so that it's not a exact tag: 另一个选择是分割字符串,以使其不是精确的标记:

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

Here's a reference explaining why it's needed, and other options: 这是解释为什么需要它的参考,以及其他选项:

Anyways, why are you writing a whole document into the <body> ? 无论如何,为什么要将整个文档写入<body>

I am not familiar with Visual Studio, but I can tell that there are some errors on your HTML architecture, You shouldn't re-insert <html><head><body> if it is already in the HTML document, also try to escape the slash: 我不熟悉Visual Studio,但是我可以告诉您HTML架构存在一些错误,如果HTML文档中已经存在<html><head><body>则不应重新插入它,也请尝试逃脱斜线:

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

If alert hello works then you are in the good track 如果警报打招呼有效,那么您就处于良好状态

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

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