jquery 正确的书写格式:
引入:
html写法:
复制代码 代码如下:
//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.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 = ;
string += 名称: haoren_内功
;
string += 当前等级:
;
string += 最大等级:
;
string += exp:
;
string += 描述:
;
string += 升级
;
string +=
;
$(#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);
},
};