//03.html
<html>
<head>
</head>
<body>
<p id="d1">所选的p元素</p>
<div>其它元素</div>
<a>其它元素</a>
</body>
</html>
//以下为load.html文档
<html>
<head>
<title>jquery的load方法使用</title>
<script type="text/javascript" src="js/jquery-1.11.1.js"></script>
<script type="text/javascript">
$(function(){
$("a").click(function(){
//只选择p元素载入到 id="context"的元素中,注意p前面要有空格
var url=this.href+" p";
//后面加参数time=new Date()是为了防止数据缓存
var args="time="+new Date();
$("#context").load(url,args);
return false;
})
})
</script>
</head>
<body>
<a href="03.html">载入</a>
<div id="context"></div>
</body>
</html>
load()方法能远程的载入HTML代码,并插入到DOM中。