且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为脚本标记一个ID

更新时间:2022-10-14 21:00:13

在当前所有浏览器中都很好。


$ b

c $ c>< script id> 错误的是Netscape 4,我们在很久很久以前就停止关注它。



那quirksmode页面似乎严重过时,使用语言属性,脚本<! - 隐藏,和 application / x-javascript 。其建议避免< body> 中的< script> (并将其放入< head> )与今天鼓励的做法不一致。

如果我们正在谈论<脚本> 属性兼容性问题: defer 无处不在,所以不要依赖它; charset 在任何地方都无法正常工作,并且所提供脚本的Content-Type上的charset参数也没有,因此脚本charset与页面匹配得更好; type 应始终为 text / javascript ,而不是编写RFC 4329你使用。


I came across a scenario where giving a script element an id attribute would solve a problem easily. However, after reading about the script element at w3schools and quirksmode, it seems doing so could have some unforeseen consequences.

Has anyone come across any of these issues with browsers such as Chrome, Safari, FF3 up and IE 7 up?

It's fine in all current browsers.

The only browser that got <script id> wrong was Netscape 4, which we stopped caring about a long, long time ago.

That quirksmode page seems to be badly out of date, what with its use of language attributes, script <!-- hiding, and application/x-javascript. Its advice about avoiding <script> in the <body> (and putting it in <head> instead) is at odds with today's encouraged practices.

If we're talking <script> attribute compatibility problems: defer doesn't work everywhere so don't rely on it; charset doesn't work everywhere, and neither does the charset parameter on the served script's Content-Type, so your script charset had better match the page; type should always be text/javascript and not one of the non-working alternatives the pedants who wrote RFC 4329 would like you to use.