jQuery的load方法载入远程 HTML 文件的执行顺序

一个html文件在浏览器中的加载顺序是顺序进行的,如下文件:



<!DOCTYPE html>
<html>
<head>
<title>a.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
alert('test');
</script>
</head>
<body>
This is my a HTML page.
<button>funa</button>
<br>
</body>

</html>



该文件直接在浏览器访问时,执行顺序是依次加载执行,先执行js中的alert,再加载body里面的内容。
不过用jQuery的load方法载入这个html文件时,该html的执行的顺序则是:首先加载完整个文档,再执行js的alert。
如果在上述html文件中加载一个js文件,<script type="text/javascript" src="test.js" charset="utf-8"></script>,变成:


<!DOCTYPE html>
<html>
<head>
<title>a.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="test.js" charset="utf-8"></script>
<script type="text/javascript">
alert('test');
</script>
</head>
<body>
This is my a HTML page.
<button>funa</button>
<br>
</body>

</html>



而test.js的内容如下:

$(document).ready(function() {
alert('onload');
});

那么load该html文件时,test.js里面的代码会执行吗?经测试,jQuery1.44会执行,jQuery1.72则不会执行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值