/*提示信息语言包*/ var dataMax = "分页输入框缺少data-max属性"; var windowTitle = "提示信息"; var windowOK = "确定"; var tooLarge = "您输入的页码过大"; var loadingMsg = "数据请求中,请稍后…"; var loading = true;//是否显示layer加载中效果 /* 使用描述 必须class tabList(选项卡循环体)、divList(列表容器循环体)、pageList(分页容器循环体)、gotobtn(go按钮)、gototext(跳转输入框) 必须属性 data-max(gototext元素上) */ function setHtml(index, msg) { //非特殊情况不需要修改 $('.divList:eq(' + index + ')').html($(msg).find('div').parents('.divList').html()); $('.pageList:eq(' + index + ')').html($(msg).find('div').parents('.pageList').html()); imgratio(); //如有回调事件 将代码放于此处即可 } //单独调用DEMO 一般用于初始第一页加载 //ajaxPageHelp('AjaxPage.html', function (msg) { // $('div.divList').html($(msg).find('div').parents('.divList').html()); // $('div.pageList').html($(msg).find('div').parents('.pageList').html()); //}) $(document).on('click', '.pageList a', function() { var index = $('.pageList').index($(this).parents('.pageList')); var href = $(this).attr('href'); if (href != 'javascript:void(0);') { ajaxPageHelp(href, function(msg) { setHtml(index, msg) }) } return false }); $(document).on('keyup', '.gototext', function() { IsNumber(this, 1) }); var regNumber = /^\d+$/; function IsNumber(obj, obj2) { if (!regNumber.test($(obj).val())) { if ($(obj).val().length > 0) { $(obj).val(obj2) } } } $(document).on('keyup', '.gototext', function(e) { var curKey = e.which; if (curKey == 13) { var index = $('.gototext').index($(this)); if ($(this).val().length == 0) { $(this).val('1') } $('.gotobtn:eq(' + index + ')').click() } }); $(document).on('click', '.gotobtn', function() { var index = $('.gotobtn').index($(this)); console.log(index); var gototext = $('.gototext:eq(' + index + ')').val(); var gotomax = $('.gototext:eq(' + index + ')').attr('data-max'); var d = $('.divList:eq(' + index + ')'); var p = $('.pageList:eq(' + index + ')'); if (gotomax == undefined) { var thisIndex = layer.alert(dataMax, { time: 0, title: windowTitle, closeBtn: 0, btn: [windowOK], yes: function(index) { layer.close(thisIndex) } }); return false } if ($(this).val().length == 0) { $(this).val('1') } if (Number(gototext) > Number(gotomax)) { var thisIndex = layer.alert(tooLarge, { time: 0, title: windowTitle, closeBtn: 0, btn: [windowOK], yes: function(index) { layer.close(thisIndex) } }); return false } var hrefTitle = ''; var hrefSuffix = ''; var regHref = /(.+)_(\d{1,})\.(.+)/; p.find('a').map(function() { if (hrefTitle.length == 0 && regHref.test($(this).attr('href'))) { hrefTitle = regHref.exec($(this).attr('href'))[1]; hrefSuffix = regHref.exec($(this).attr('href'))[3] } }); if (hrefTitle.length > 0) { var href = ""; if (Number(gototext) == 1) { href = hrefTitle + "." + hrefSuffix } else { href = hrefTitle + "_" + gototext + "." + hrefSuffix } ajaxPageHelp(href, function(msg) { setHtml(index, msg) }) } }); function ajaxPageHelp(url, fn) { if (loading) { var thisIndex = layer.msg(loadingMsg, { time: 0, icon: 16 }) } $.ajax({ "type": "get", "url": "" + url + "", "datatype": "html", "success": function(msg) { if (loading) { layer.close(thisIndex) } if (fn) { fn(msg) } }, "error": function() { if (loading) { layer.close(thisIndex) } } }) }