在< script>中执行代码标记与外部源 [英] Executing code inside a <script> tag with an external source

查看:66
本文介绍了在< script>中执行代码标记与外部源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个片段:

<script type="text/javascript">
alert("1111");
</script>  

<script type="text/javascript" src="xxx.js">
</script>

导致1111被警告,但是这一个:

result in "1111" being alerted, but this one:

<script type="text/javascript" src="xxx.js">

alert("111");
</script>

不会导致111发出警报?是否无法将代码放入加载外部脚本的相同< script> 标记中?

doesn't cause "111" to alert? Is it not possible to put code in the same <script> tag that loads an external script?

推荐答案

嗯,这就是< script> 标签的工作原理。如果您有 src 属性,则会忽略该标记的内容。

Well, this is just how the <script> tag works. If you have a src attribute, the content of the tag gets ignored.

只需使用其他< script> 标签,有什么问题?

Simply use another <script> tag, what's the problem with that?

这篇关于在&lt; script&gt;中执行代码标记与外部源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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