Home  >  Article  >  Web Front-end  >  The correct way to write jQuery function_jquery

The correct way to write jQuery function_jquery

WBOY
WBOYOriginal
2016-05-16 17:27:021747browse
The correct writing format of jQuery:
Introduction:
HTML writing:
Copy code The code is as follows:






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


//XXXXXXXXXXXXXX

jQuery writing:
var qiyiPlugin =
{
init: function(parentNode) {
var self = this;
self.parentNode = parentNode;
//Refresh local content
self.parentNode
.on('refresh',function(event){
self.qiyiList();
});
},
//Display
qiyiList: function(){
var self = this;
//Display internal strength information
self.getQiyiList(function(result){
//console.log(result ; >}else{
alert("Qiyi data was not obtained, please check the interface");
}
});
},
//Display Qiyi content
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);//Additional attributes data and information
$(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() ;//Change the attrs attribute
self.parentNode.trigger('refresh');
}
});
});
});
},
//Assign html value -
qiyiHtml1: function() {
var string = "";
string = "";
string = "";
string = "Maximum level:";
string = "";
string = "";
string = "";
string = "";
$("#zong_qiyi").html(string);
},
/ /Qiyi Upgrade
clickToUpgradeQiyi: function(info,callback) {
var query = "operation=upgradeQiyi";
query = "&qiyiName=" info.name;
toolsPlugin.play(query, callback);
},
//Get Qiyi List
getQiyiList: function(callback) {
var query = "operation=getQiyiList";
toolsPlugin.play(query,callback) ;
},
};

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn