带有src和内容的脚本标记是什么意思? [英] What does a script-Tag with src AND content mean?

查看:131
本文介绍了带有src和内容的脚本标记是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Googles的示例+1按钮:

Example from Googles +1 button:

<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
      {"parsetags": "explicit"}
</script>

脚本标签包含src-Attribute 内容。这是什么意思,它是如何工作的?

The script Tag has a src-Attribute and content. What does this mean and how does it work?

推荐答案

不同的浏览器对此有不同的看法。有些只在包含 src 且没有错误的情况下运行内容。有些人在尝试包含 src 脚本后运行它,无论成功与否。由于此行为不可靠(并在HTML5中禁止) ,应该避免。

Different browsers treat this differently. Some run the content only if the src is included without error. Some run it after attempting to include the src script, regardless of success. Since this behaviour is unreliable (and prohibited in HTML5), it should be avoided.

Google并不依赖于任何特定行为。由于内容只是一个对象文字(一个值),执行它实际上不会做任何事情,除了导致无声错误。 Google的代码会查看脚本标记本身的内容,并根据该标记调整其行为。

Google isn't relying an any specific behaviour. Since the content is just an object literal (a value), executing it would not actually do anything except cause a silent error. Google's code looks at the contents of the script tag itself, and adjust its behaviour based on that.

这篇关于带有src和内容的脚本标记是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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