2010-08-22 140 views
13

我想知道如果一个脚本标记同时具有“src”和内联脚本。我尝试了下面的代码。如果script标签同时包含“src”和内联脚本,该怎么办?

<script src="http://yui.yahooapis.com/2.8.1/build/yahoo/yahoo-min.js" type="text/javascript" charset="utf-8"> 
     alert('hello'); 
</script> 
<script type="text/javascript" charset="utf-8"> 
     alert(YAHOO); 
</script> 

“alert('hello')”似乎从未在Firefox和Chrome中执行过。我试图将src改为指向不存在的URI。 “alert('hello')”也不会被执行。

那么,如果脚本标记中有src属性,内联脚本总是被忽略?

+0

它为什么重要? :) – jtbandes 2010-08-22 07:34:29

+1

可能重复[JavaScript:内联脚本与SRC属性?](http://stackoverflow.com/questions/1056325/javascript-inline-script-with-src-attribute) – 2010-11-21 11:25:12

回答

9

jquery的创始人约翰·雷斯格(John Resig)曾在an interesting post的帮助下解决了这个限制,并尝试了使其工作的方法,但他并不推荐实际使用这些方法。