JavaScript:具有SRC属性的内联脚本? [英] JavaScript: Inline Script with SRC Attribute?

查看:94
本文介绍了JavaScript:具有SRC属性的内联脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于像这样包括和使用JS:

I'm used to including and using JS like so:

<script type='text/javascript' src='/path/to/script.js'></script>
....
<script type='text/javascript'>
    alert('Do some stuff here, using resources defined in script.js.');
</script>

出于好奇,有没有人知道带有src attrib的内联脚本的规则,比如:

Just out of curiosity, does anyone know the rule for having an inline script with a src attrib, like:

<script type='text/javascript' src='/path/to/script.js'>
    alert('Do some stuff here, using resources defined in script.js.');
</script>

我可以测试各种浏览器会发生什么,但想知道官方行为是什么。

I can test what DOES happen in various browsers, but would like to know what the official behavior is.

推荐答案

它是一个或另一个,而不是两者。 < script> 标记的 src 属性优先于标记正文。

It's either one or the other, not both. The src attribute of the <script> tag has precedence over the body of the tag.

HTML 4.01规范


脚本可以在SCRIPT元素的
内容中定义,也可以在
中定义外部文件。如果未设置 src 属性
,则用户代理必须将
元素的内容解释为
脚本。如果 src 具有URI值,
用户代理必须忽略元素的
内容并通过
URI检索脚本。

The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.

这篇关于JavaScript:具有SRC属性的内联脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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