Ajax实现搜索功能的分页(ajax分类筛选)越早知道越好

随心笔谈1年前 (2023)发布 admin
143 0


<script type=”text/javascript”>
//清空最大页和当前页,保证能够多次搜索
function on()
{
$(‘#pageCurrent’).val(”);
$(‘#maxys’).val(”);
}
//首页
function pageAjaxFirst()
{
$(‘#pageCurrent’).val(1);
searchResult();
}
//尾页
function pageAjaxEnd()
{
var maxys=$(‘#maxys’).val();
$(‘#pageCurrent’).val(maxys);
searchResult();
}
//下一页
function pageAjaxNext()
{
var maxys=$(‘#maxys’).val();
var page=$(‘#pageCurrent’).val();
$(‘#pageCurrent’).val(parseInt(page) +1);
if (page > maxys) {
$(‘#pageCurrent’).val(maxys);
}
searchResult();
}
//上一页
function pageAjaxPrev()
{
var maxys=$(‘#maxys’).val();
var page=$(‘#pageCurrent’).val();
$(‘#pageCurrent’).val(parseInt(page) -1);
if (page < 1) {
$(‘#pageCurrent’).val(1);
}
searchResult();
}
//跳转页面
function tiao ()
{
var maxys=$(‘#maxys’).val();
var now=$(‘#pageTiao’).val();
$(‘#pageCurrent’).val(now);
var page=$(‘#pageCurrent’).val();
if (page < 1) {
$(‘#pageCurrent’).val(1);
}
if (page > maxys) {
$(‘#pageCurrent’).val(maxys);
}
searchResult();

}
function searchResult()
{

var formData=$(“#myPost”).serialize();
var caption=$(“#caption”);
var html=”;

$(‘#pageBar’).remove();
$.ajax({
type:”get”,
url:”/user/search/do_search”,
data:formData,
success:success,
error: fail
});

function fail() {
alert(‘查询条件有误。’)
}
function success(search){
if (search !=null) {
var obj=JSON.parse(search);
var content=obj[0];
var nowPage=obj[1];
var total1=obj[2];
var allPage=obj[4];
$.each(content, function (key, value) {
html +='<tr class=”sousuo”><td class=”chk”><input value=”” val=”‘ + content[key][‘user_id’] + ‘” type=”checkbox” name=”CheckBox[‘ + content[key][‘user_id’] + ‘]” class=”check-box” /></td> <td class=”txt40 c”>’ + content[key][‘user_id’] + ‘</td><td class=”txt40 c”><a href=”https://www.jb51.net/user/user/user_info/user_id/’ + content[key][‘user_id’] +'” rel=”external nofollow” ‘ + ‘”title=”查看资料”>’+ content[key][‘account’] + ‘</a></td>’ + ‘<td class=”txt40 c”>’ + content[key][‘nickname’]+ ‘</td><td class=”txt40 c”>’ + content[key][‘sex’] + ‘</td><td class=”txt80 c”>’ + content[key][‘coin’] + ‘</td><td class=”txt40 c”>’ + content[key][‘tickets’] + ‘</td><td class=”txt40 c”>’ + content[key][‘gem’] + ‘</td><td class=”txt40 c”>VIP’ + content[key][‘vip_id’] + ‘</td><td class=”txt40 c”>’ + content[key][‘user_type’] + ‘</td> <td class=”txt80 c”>’ + content[key][‘register_platform’] + ‘ </td> <td class=”txt80 c”>’ + content[key][‘register_date’] + ‘</td> <td class=”txt80 c”>’+content[key][‘last_login_time’] + ‘</td><td class=”txt80 c”>’+ content[key][‘last_login_ip’] + ‘</td> <td class=”txt80 c”>’+ content[key][‘game_login_times’] +'</td><td class=”txt80 c”>’+ content[key][‘prohibit_flag’] + ‘</td><td class=”icon”><a class=”opt” title=”编辑” href=”https://www.jb51.net/user/user/edit_user/user_id/’ + content[key][‘user_id’] + ‘}” rel=”external nofollow” ><span class=”icon-sprite icon-edit”></span></a></td></tr>’;
});
$(‘.showTr’).remove();
$(‘.sousuo’).remove();
$(‘.xiaoshi’).remove();

$(‘.show’).after(html);
$(‘#maxys’).val(allPage);
$(‘#pageCurrent’).val(nowPage);
} else {
$(‘.show’).after(‘<tr>没有数据</tr>’);
}
$(‘#fenye’).css(‘display’,’block’);
$(‘#pageAjax’).html(‘页次:’+ nowPage + ‘/’ + allPage +’每页22总数’ + total1);
}
}
</script>

© 版权声明

相关文章