What if script tag has both “src” and inline script? [duplicate]

强颜欢笑 提交于 2019-12-17 07:39:59

问题


I am wondering what if one script tag has both "src" and inline script. I tried below code.

<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>

It the "alert('hello')" seems never executed in Firefox and Chrome. I tried to change the src to point to non-existent URI. The "alert('hello')" is also not executed.

So, inline script is always ignored if there is src attribute in script tag?


回答1:


John Resig, founder of jQuery, had an interesting post awhile back that addressed this limitation and experimented with ways to make it work, none of which he would recommend actually using.




回答2:


John Resig wrote about this topic a couple years ago. I thought it was a good read :)



来源:https://stackoverflow.com/questions/3540581/what-if-script-tag-has-both-src-and-inline-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!