异步加载script的代码

时间:2011-01-12    点击:176   
通过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>
Jquery知识点一 Jquery的ready和Dom的onload的区别
JavaScript去掉数组中的重复元素
javascript基础知识大集锦(二) 推荐收藏
javascript基础知识大集锦(一) 推荐收藏
myFocus slide3D v1.1.0 使用方法与下载
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved