熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

jQuery function的正確書寫方法

2022-06-13   來源: JSP教程 
jQuery function想必大家都不會陌生web前端開發人員經常會接觸到下面為大家介紹下它的正確書寫方法感興趣的朋友可以參考下  

  jQuery 正確的書寫格式
引入<script src="/libs/jquery/jqueryjs" type="text/javascript"></script>
html寫法

復制代碼 代碼如下:

  
<html>
<head>
<meta httpequiv="ContentType" content="text/html; charset=utf"/>
<title></title>
<script src="modulesjs/qiyijs"></script>
<script>
$(function() {
qiyiPlugininit($("#zong_qiyi"));
});
</script>
</head>
<div id="zong_qiyi">
//XXXXXXXXXXXXXX
</div>
jQuery寫法
var qiyiPlugin =
{
init: function(parentNode) {
var self = this;
selfparentNode = parentNode;
//刷新局部內容
selfparentNode
on(refreshfunction(event){
selfqiyiList();
});
}
//顯示
qiyiList: function(){
var self = this;
//顯示內功信息
selfgetQiyiList(function(result){
//consolelog(result);
if(resultqiyiList){
selfqiyiHtml();//重新覆蓋html防止重復顯示內容
selfdisplayQiyiList(resultqiyiList);//展示頁面內容
}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 line = $(top)find("#qiyi_control_panel");
$each(qiyiListfunction(indexitem){
var line = $(line)clone();
$(line)data(dataitem);//附加屬性data與信息
$(line)attr(idindex+);
$(line)find("#name")html(itemname);
$(line)find("#level")html(itemlevel);
$(line)find("#maxLevel")html(itemmaxLevel);
$(line)find("#exp")html(itemexp+"/"+itemneedExp);
$(line)find("#desc")html(itemdesc);
$(line)before(line);
$(line)show();
$(line)find("#upgrade")
on(clickfunction(event){
var table = $(this)parents(table:first);
var info = $(table)data(data);
selfclickToUpgradeQiyi(info function(result){
if(!resultsuccess){
alert(resultfaildesc);
}else{
//alert(resultsuccessdesc);
growingPluginplayerTopData();//改變attrs屬性
selfparentNodetrigger(refresh);
}
});
});
});
}
//賦html值
qiyiHtml: function() {
var string = "<table id=qiyi_control_panel class=table tablebordered tablehover style=display:none; width:;>";
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=desc></td></tr>";
string += "<tr><td><button id=upgrade class=btn btnlink>升級</button></td></tr>";
string += "</table>";
$("#zong_qiyi")html(string);
}
//奇藝升級
clickToUpgradeQiyi: function(infocallback) {
var query = "operation=upgradeQiyi";
query += "&qiyiName=" + infoname;
toolsPluginplay(querycallback);
}
//獲得奇藝列表
getQiyiList: function(callback) {
var query = "operation=getQiyiList";
toolsPluginplay(querycallback);
}
};


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20658.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.