带有src的脚本标记和脚本标记之间的代码 [英] Script tags with src and code between script tags

查看:156
本文介绍了带有src的脚本标记和脚本标记之间的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是有效的javascript吗?该变量是否可用于外部调用的脚本?

Is the following valid javascript? Would the variable be available to the externally called script?

<script src="//blah">

var something = "";

</script>

背景:我已经看到这用于自动生成的分析代码(不是谷歌),它真的让我烦恼所以想知道我是否可以解决这个问题,或者这个变量是否会以某种方式被外部引用的脚本使用。

Background: I have seen this used in auto generated analytic code (not google) and it really annoys me so wanting to know if i can fix this or if this variable will somehow be used by the externally referenced script.

推荐答案

阅读本文, http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1


脚本可以在SCRIPT元素的内容中定义,也可以在外部文件中定义。如果未设置src属性,则用户代理必须将该元素的内容解释为脚本。如果src具有URI值,则用户代理必须忽略该元素的内容并通过URI检索脚本。注意,charset属性是指src属性指定的脚本的字符编码;它与SCRIPT元素的内容无关。

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. Note that the charset attribute refers to the character encoding of the script designated by the src attribute; it does not concern the content of the SCRIPT element.

这篇关于带有src的脚本标记和脚本标记之间的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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