jQuery基于xml格式数据实现模糊查询及分页功能的方法

2020-05-27 17:53:32易采站长站整理

$.pageto(pagenum,$.resultdata,$("#"+id+" ul"));
$.pagetool.pageto(pagenum);
}else{
pagenum++;
}
});
$("#pagetool .down").click(function(){
pagenum++;
if(pagenum<=$.pagetotal){
$("#pagetool span").css("backgroundColor",'white');
$("#pagetool span[pagenum='"+pagenum+"']").css("backgroundColor",'lightblue');
$.pageto(pagenum,$.resultdata,$("#"+id+" ul"));
$.pagetool.pageto(pagenum);
}else{
pagenum--;
}
});
});
};
//工具栏分页
$.pagetool = {
createpagetool : function(pagetotal) {
var html = "<span class='up'>up</span>";
var pagetoolpagenum=1;
for (var i = 1; i <= pagetotal; i++) {
if(i%5==1&&i>5){
pagetoolpagenum++;
}
html += "<span pagenum='"+i+"' i='" +pagetoolpagenum + "' class='num'>" + i
+ "</span>";
}
html += "<span class='down'>down</span>";
$("#pagetool").html(html);
},
pageto : function(pagenum,pagetotal) {
var pagetoolpagenum=1;
if(pagenum>5){
pagetoolpagenum=Math.ceil(pagenum/5);
}
$("#pagetool span").hide();
$("#pagetool span:first").show();
$("#pagetool span[i='"+pagetoolpagenum+"']").show();
$("#pagetool span:last").show();
}
};
//模糊搜索
$.indexsearch=function(indexdata,keyword){
var resultids=new Array();
for (var key in $.indexdata){
if(key.indexOf(keyword)!=-1)
resultids.push($.indexdata[key]);
}
return resultids;
};
//跳页程序
$.pageto=function(pagenum,data,obj){
var list=data[pagenum];
var html="";
obj.html(html);
obj.parent().show();
$(list).each(function(i){
try{
html+='<li id="'+list[i]+'" >'+$.jsondata].JGMC+'</li>';
}catch(e){}
});
obj.html(html);
obj.find("li").bind({//结果集的点击事件
"click":function(){
$.select($(this));
obj.parent().hide();
obj.parent().find("#pagetool").html("");
},
"mouseover":function(){//结果集的鼠标悬浮事件
$(this).parent().find("li").css("backgroundColor","white");
$(this).css("backgroundColor","lightblue");
}
});
};
}(jQuery));

在页面中调用


<div class="item_input fl">
<input id="reg_companyname" autocomplete="off" type="text" class="text" name="DWBM_SV"/>
<div id="resultlist" class="hidden" style="width:300px;margin-top: 1px;display:none;">