$.getScript()方法


<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>1111</title>
<script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script>
</head>
<body>
<div class="content">
<p><input type="button" id="send" value="加載"/></p>
<div id="resText">
<h4>已有評論:</h4>
</div>
</div>

<script type="text/javascript">
$(function(){
$("#send").click(function() {
$.getScript("test.js");
});
})
</script>
</body>
</html>

加載的test.js文件,代碼如下

var comments=[
{
"name" : "黎明",
"msg" : "學生"
},
{
"name" : "小麗",
"msg" : "學生"
},
{
"name" : "大華",
"msg" : "學生"
},
{
"name" : "李麗",
"msg" : "學生"
},
{
"name" : "李靜",
"msg" : "學生"
}
];
var html="";
$.each(comments,function(index, comment) {
html +="<div class='comment'><h5>"+comment['name']+"</h5><p>"+comment['msg']+"</p></div>"
});
$("#resText").append(html);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM