简体   繁体   English

对有关脚本标记类型属性的特殊JavaScript问题感到好奇

[英]Curious about peculiar JavaScript issue regarding script tag type attribute

So, my team is using the HTML5 Boilerplate and has the site nearly finished. 所以,我的团队正在使用HTML5 Boilerplate并且网站已经完成了。 I want to do a quick JavaScript test to make sure the client can add their own JavaScript if they so desire. 我想做一个快速的JavaScript测试,以确保客户端可以添加自己的JavaScript,如果他们愿意的话。 I know the type attribute for the script tag is not required when using the HTML5 doctype, but the JavaScript alert doesn't even work when it's used (which is what has me confused as I've built HTML5 sites while using the type attribute in the script tag. 我知道在使用HTML5文档类型时不需要脚本标记的type属性,但JavaScript警报在使用时甚至不起作用(这使我感到困惑,因为我在使用type属性时构建了HTML5网站脚本标记。

What works: 什么有效:

    <script>        
      alert("HELP");        
    </script>

What doesn't work: 什么行不通:

    <script type="text/javascript">     
      alert("HELP");        
    </script>

Can anyone explain what's going on? 谁能解释一下发生了什么? This DOES work for other HTML5 based websites... 这适用于其他基于HTML5的网站......

***Tested with Firefox 12 on Ubuntu 12.04 ***在Ubuntu 12.04上使用Firefox 12进行测试

Thanks guys. 多谢你们。

PS It's not going to make or break the site, is not very important, etc. I was just wondering why this problem exists. PS它不会打破或破坏网站,不是很重要,等等。我只是想知道为什么这个问题存在。

EDIT 编辑

Here's a link to a publically hosted page that WORKS. 这是一个工作的公开托管页面的链接。

http://illinois.edu/1500/index.html http://illinois.edu/1500/index.html

Why does it not work on my local box (shakes head)...? 为什么它不适用于我当地的盒子(摇头)......?

Both versions are correct and should work. 两个版本都是正确的,应该可行。 Either there's a problem in your code like a missing tag or more likely you've checked the "Prevent this page from creating aditional dialogs" checkbox. 您的代码中存在问题,例如缺少标记,或者您更有可能检查了“阻止此页面创建aditional对话框”复选框。

Replace your alerts with this and try it out in Chrome: 用此替换您的提醒并在Chrome中试用:

<script type="text/javascript">
console.log('HELP');
</script>
<script>
console.log('HELP');
</script>

Now run the page in Chrome, press F12 go to Console and see if the messages pop up 现在在Chrome中运行该页面,按F12转到控制台,查看是否弹出消息

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

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