load()方法

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>loading</title>
<script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<style>
.container{
width: 60%;
margin: 0 auto;
border:1px solid #666;
}
.comment{
background-color: #cfcfcf;
}

</style>
</head>
<body>
<div class="container">
<input type="button" id="send" value="Ajax获取">
<div class="comment">已有评论</div>
<div id="resText"></div>
</div>
<script type="text/javascript">
$("#send").click(function() {
$("#resText").load("text.html",function(responseText,textStatus,XMLHttpRequest) {
alert(responseText);
alert(textStatus);
alert(XMLHttpRequest);

});
});n
</script>
</body>
</html>

//要加载的文件text.html,如下代码

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>loading</title>
</head>
<body>
<div class="comment">
<h6>张三</h6>
<p class="para">学生1</p>
</div>
<div class="comment">
<h6>李四</h6>
<p class="para">学生2</p>
</div>
<div class="comment">
<h6>小明</h6>
<p class="para">学生3</p>
</div>
</body>
</html>

 

posted @ 2017-04-18 13:29  代码小精灵  阅读(373)  评论(0编辑  收藏  举报