首頁  >  文章  >  web前端  >  jQuery function的正確書寫方法_jquery

jQuery function的正確書寫方法_jquery

WBOY
WBOY原創
2016-05-16 17:27:021744瀏覽
jQuery 正確的書寫格式:
引入:
html寫法:
複製程式碼 程式碼如下:




<script> <BR>$(function() { <BR>qiyiPlugin.init($("#zong_qiyi")); <BR>}); <BR></script>


//XXXXXXXXXXXXXX

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.qiyiHself. ();//重新覆蓋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){
$.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.parent.trigger('refresh' );
}
});
});
});
},
//賦html值-
qiyiHtml1: function() {
var string = "";
string = "";
string = "";
string = "";
string = " ";
string = "";
string = "";
string = "";
$("#zong_qiyi").html(string);
},
//奇藝升級
clickToUpgradeQiyilick : 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); >};

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn