js实例教程-jQuery function的正确书写方法

发布时间:2018-12-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例教程-jQuery function的正确书写方法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

jQuery 正确的书写格式:
引入:<script src="/libs/jquery/jquery.js" tyPE="text/javascript"></script>
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>
<p id="zong_qiyi">
//XXXXXXXXXXXXXX
</p>
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 += "&amp;qiyiName=" + info.name;
toolsPlugin.play(query,callback);
},
//获得奇艺列表
getQiyiList: function(callback) {
var query = "operation=getQiyiList";
toolsPlugin.play(query,callback);
},
};

jQuery 正确的书写格式:
引入:<script src="/libs/jquery/jquery.js" type="text/javascript"></script>
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>
<p id="zong_qiyi">
//XXXXXXXXXXXXXX
</p>
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);
},
};

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例教程-jQuery function的正确书写方法全部内容,希望文章能够帮你解决js实例教程-jQuery function的正确书写方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。