异步加载script的代码

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

异步加载script的代码

  2020-05-12 我要评论
通过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>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们