$.getScript,可以给包含的脚本一个id吗?
通过jquery的$.getScript方法,你可以给包含的脚本一个DOM id吗?
所以生成的代码应该是:
<script type="text/javascript" id="xxxxxx" src="..."></script>
我知道我可能可以自己编写该行,但是 $.getScript 一定是有原因的,对吧? (跨浏览器兼容性等?)
Via jquery's $.getScript method, can you give the included script a DOM id?
So generated code should be:
<script type="text/javascript" id="xxxxxx" src="..."></script>
I know I could probably just document.write that line myself, but $.getScript must be there for a reason right? (cross browser compatibility, etc?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这可能已经在这里被回答/讨论过:为什么调用 $.getScript 而不是使用
getScript 允许您在需要延迟加载脚本的情况下、在您希望在脚本加载时获得状态回调的情况下或在无法使用脚本的情况下动态加载脚本标签。
getScript 有一些缺点,因为它受同源策略的约束,而 script 标签则不然。
如果看到其他网页在脚本标签上放置了 ID (smugmug.com),但我也看到在测试标准的合规性时将其标记为非标准。它似乎可以工作并被其他人使用,但我猜它不是标准的。
I think this has maybe been answered/discussed before here: Why call $.getScript instead of using the <script> tag directly?.
getScript allows you to dynamically load a script in situations where it's either desirable to delay the loading of the script, in situations where you want to get a status callback on when the script has been loaded or in situations where you couldn't use a script tag.
getScript has some downsides in that it's subject to the same-origin policy whereas a script tag is not.
If have seen other web pages put an ID on a script tag (smugmug.com), but I've also seen that flagged as non-standard when testing standard's compliance. It seems to work and be used by others, but I'm guessing it isn't standard.