异步加载script的代码
更新时间:2011年01月12日 22:22:20 作者:
通过异步请求另一页面的script 是不执行的,只返回html 原文件,因为返回的文本没有经过浏览器的解析执行。
通过iframe 异步加载script
通过异步请求另一页面的script 是不执行的,只返回html 原文件,因为返回的文本没有经过浏览器的解析执行。
看代码
a1.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<script type="text/javascript">
function testClick()
{
document.getElementById("tsrc").src="a2.html"
}
</script>
<body>
<div style="display:none"><iframe id="tsrc"></iframe></div>
<input id="Button1" type="button" value="异步加载script" onclick="testClick()"/>
</body>
</html>
a2.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<body>
<script>
alert('我是异步script');
</script>
</body>
</html>
通过异步请求另一页面的script 是不执行的,只返回html 原文件,因为返回的文本没有经过浏览器的解析执行。
看代码
a1.html
复制代码 代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<script type="text/javascript">
function testClick()
{
document.getElementById("tsrc").src="a2.html"
}
</script>
<body>
<div style="display:none"><iframe id="tsrc"></iframe></div>
<input id="Button1" type="button" value="异步加载script" onclick="testClick()"/>
</body>
</html>
a2.html
复制代码 代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<body>
<script>
alert('我是异步script');
</script>
</body>
</html>
相关文章
单元测试框架Jest搭配TypeScript的安装与配置方式
这篇文章主要介绍了单元测试框架Jest搭配TypeScript的安装与配置方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-01-01javascript foreach中如何获取数组下标/index
这篇文章主要介绍了javascript foreach中如何获取数组下标/index问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-07-07
最新评论