HTML脚本标签-使用src时可以添加脚本 [英] Html script tag - can script be added when src is used

查看:79
本文介绍了HTML脚本标签-使用src时可以添加脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有src属性的html脚本标记,如下所示:

I'm using an html script tag with the src attribute as follows:

<script src="http://...">
</script>

在脚本运行后,我还需要添加一些代码来重定向页面-在现有脚本标记之间添加脚本是否有效/可以接受,还是应该在末尾添加其他脚本?

I need to also put a bit more code to redirect the page after the script has run - is it valid/acceptable to add the script between the existing script tags or should I add another script on the end?

此:

<script src="http://...">
    ...do something else he
</script>

或者:

<script src="http://...">
</script>
<script>
    ...my other code here
</script>

推荐答案

不行.

使用最下面的一个.

答案很长……

w3c状态

"SCRIPT元素将脚本放置在文档中.该元素可以在HTML文档的HEAD或BODY中出现任意次数.

"The SCRIPT element places a script within a document. This element may appear any number of times in the HEAD or BODY of an HTML document.

脚本可以在SCRIPT元素的内容内或外部文件中定义.如果未设置src属性,则用户代理必须将元素的内容解释为脚本.如果src具有URI值,则用户代理必须忽略元素的内容,并通过URI检索脚本."

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

来源: http://www.w3.org/TR/html401/interact/scripts.html

这篇关于HTML脚本标签-使用src时可以添加脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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