jQuery function 의 정확 한 쓰기 방법

3860 단어 jQueryfunction
jQuery 올 바른 쓰기 형식:도입:html 쓰기:
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="modules-js/qiyi.js"></script>
<script>
$(function() {
qiyiPlugin.init($("#zong_qiyi"));
});
</script>
</head>
<div id="zong_qiyi">
//XXXXXXXXXXXXXX
</div>
jQuery :
var qiyiPlugin =
{
init: function(parentNode) {
var self = this;
self.parentNode = parentNode;
//
self.parentNode
.on('refresh',function(event){
self.qiyiList();
});
},
//
qiyiList: function(){
var self = this;
//
self.getQiyiList(function(result){
//console.log(result);
if(result.qiyiList){
self.qiyiHtml1();// html,
self.displayQiyiList(result.qiyiList);//
}else{
alert(" , ");
}
});
},
//
displayQiyiList: function(qiyiList){
var self = this;
var top = "#zong_qiyi";
$(top).find('#qiyi_control_panel').each(function(){
if ($(this).data('data')) $(this).remove();
});
var line0 = $(top).find("#qiyi_control_panel");
$.each(qiyiList,function(index,item2){
var line1 = $(line0).clone();
$(line1).data('data',item2);// data
$(line1).attr('id',index+1);
$(line1).find("#name").html(item2.name);
$(line1).find("#level").html(item2.level);
$(line1).find("#maxLevel").html(item2.maxLevel);
$(line1).find("#exp").html(item2.exp+"/"+item2.needExp);
$(line1).find("#desc1").html(item2.desc1);
$(line0).before(line1);
$(line1).show();
$(line1).find("#upgrade")
.on('click',function(event){
var table = $(this).parents('table:first');
var info = $(table).data('data');
self.clickToUpgradeQiyi(info, function(result){
if(!result.success){
alert(result.fail.desc1);
}else{
//alert(result.success.desc1);
growingPlugin.playerTopData();// attrs
self.parentNode.trigger('refresh');
}
});
});
});
},
// html -
qiyiHtml1: function() {
var string = "<table id='qiyi_control_panel' class='table table-bordered table-hover' style='display:none; width:500;'>";
string += "<tr><td> :</td><td id=name>haoren_ </td></tr>";
string += "<tr><td> :</td><td id=level></td></tr>";
string += "<tr><td> :</td><td id=maxLevel></td></tr>";
string += "<tr><td>exp:</td><td id=exp></td></tr>";
string += "<tr><td> :</td><td id=desc1></td></tr>";
string += "<tr><td><button id='upgrade' class='btn btn-link'> </button></td></tr>";
string += "</table>";
$("#zong_qiyi").html(string);
},
//
clickToUpgradeQiyi: function(info,callback) {
var query = "operation=upgradeQiyi";
query += "&qiyiName=" + info.name;
toolsPlugin.play(query,callback);
},
//
getQiyiList: function(callback) {
var query = "operation=getQiyiList";
toolsPlugin.play(query,callback);
},
};

좋은 웹페이지 즐겨찾기