如果脚本标记同时包含“src”,该怎么办?和内联脚本? [英] What if script tag has both "src" and inline script?

查看:96
本文介绍了如果脚本标记同时包含“src”,该怎么办?和内联脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果一个脚本标签同时具有src和内联脚本会是什么。我试过下面的代码。

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>

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

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.

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

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

推荐答案

jQuery创始人John Resig有一篇有趣的帖子,后来解决了这个限制,并尝试了使其成功的方法,但他没有建议实际使用。

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.

这篇关于如果脚本标记同时包含“src”,该怎么办?和内联脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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