为什么我要在脚本标签上放一个ID? [英] Why would I put an ID on a script tag?

查看:96
本文介绍了为什么我要在脚本标签上放一个ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到有些网站开发人员将ID放在脚本标签上。例如:

 < script id =scriptysrc =something.jstype =text / javascript> ;< /脚本> 

我知道根据W3C这是完全合法的标记,但是这样做的好处是什么? / p>

解决方案

我见过的一个用法是,如果您想为客户提供小部件,并指示他们将< script> 标签,无论他们想要显示小部件。如果你给< script> 元素一个ID,那么你可以引用它内部的代码放置在正确的位置。这并不是说它只是 实现的方式,当然,但我已经看到它完成了在过去推荐它

I've noticed that some web developers put IDs on scripts tags. For example:

<script id="scripty" src="something.js" type="text/javascript"></script>

I know that according the W3C this is perfectly legal markup, but what's the benefits of doing this?

解决方案

The one use I've seen of this is if you want to provide widget for customers and you instruct them to place the <script> tag wherever they want the widget to show up. If you give the <script> element an ID then you can reference that inside of it to place the code in the right place. That's not to say that it is the only way of achieving that, of course, but I've seen it done and suggested it in the past.

这篇关于为什么我要在脚本标签上放一个ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆