代码是这样的:
var script = document.createElement('script');
//script.type = 'text/javascript'; // do I need this ?
script.src = src;
document.body.appendChild(script);
Run Code Online (Sandbox Code Playgroud)
第二行已被注释掉,因为它没有任何区别.或者我错过了什么?
谢谢,
否:默认值type已设置为JavaScript("text/javascript").type属性是SCRIPT标记的一个属性,允许Vbscript,例如,只有IE支持.
该type属性在HTML5中也是可选的.这可能是一种省略元素type属性的鼓励script.
不.它可能在html4中并不完全正确,但它不会给你带来任何问题.
"The type attribute gives the language of the script or format of the data..."
"...The default, which is used if the attribute is absent, is 'text/javascript'."
Run Code Online (Sandbox Code Playgroud)
我唯一注意到的是,当您未指定类型时,IDE有时不会使用正确的语法突出显示.我在Coda for Mac中找到了这个,这是我现在把它放进去的唯一原因.
| 归档时间: |
|
| 查看次数: |
2497 次 |
| 最近记录: |