锘?/"use strict";
var isDebug = getUrlParameter("debug", "1", $('#jsBase').attr('src'));
if (isDebug == "1") {
isDebug = true;
}
else {
isDebug = false;
}
$(function () {
//initIEPlaceholder();
})
/**
* 鑾峰彇IE鐗堟湰 ,闈濱E 杩斿洖99*/
function IEBrowserVersion() {
var userAgent = navigator.userAgent;
//鍒ゆ柇鏄惁IE娴忚鍣
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
if (isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
return fIEVersion;
} else {
if (!!window.ActiveXObject || "ActiveXObject" in window)
return 11;
else
return 99;
}
return 99;
}
/**
* 鍒濆鍖朓E鎯呭喌涓嬭緭鍏ユ涓璸laceholder 鍙樺寲*/
function initIEPlaceholder() {
if (IEBrowserVersion() < 10) {
if ($("input[type='text']").length > 0) {
$("input[type='text']").each(function () {
var input = $(this);
if (input.attr("placeholder") != undefined) {
if (input.val() == "") {
input.val(input.attr("placeholder"));
input.css("color", "#999");
}
input.bind("blur", function () {
if ($(this).val() == "") {
$(this).val($(this).attr("placeholder"));
$(this).css("color", "#999");
} else {
$(this).css("color", "");
}
});
input.bind("focus", function () {
if ($(this).val() == $(this).attr("placeholder")) {
$(this).val("");
$(this).css("color", "");
}
});
input.bind("keypress", function () {
$(this).css("color", "");
})
}
})
}
}
}
function htmlAppendToElement(html, element) {
if (IEBrowserVersion() < 99) {
element.append($(html));
} else {
element.append(html);
}
}
/**
* 鎻愮ず鏂囧瓧淇℃伅,璋冪敤姝ゆ柟娉曞繀椤诲紩鐢 layer.js
* @param {String} icontype 鎻愮ず鍥炬爣,鍙€夊€机success銆乪rror銆乼ips銆乴oading銆?"
* @param {String} str 鎻愮ず鐨勬枃瀛椾俊鎭
* @param {Int} daleytime 鎻愮ず鎸佺画鏃堕棿,鍗曚綅绉
* @param {function} callBack 鎻愮ず鍚庢墽琛岀殑鍑芥暟
*/
function tips(icontype, str, daleytime, callBack) {
// icon:(0:鎰熷徆鍙?1:OK,2:閿欒,3:闂彿,4:閿?5:鍝劯,6:绗戣劯,16:鍔犺浇涓?
if (daleytime.length == 0 || isNaN(daleytime)) {
daleytime = 3;
}
var _time = parseInt(daleytime);
if (icontype == "error") {
layer.msg(str, { time: _time * 1000, offset: 'auto' }, function () { if (callBack != undefined) { callBack(); } });
} else if (icontype == "success") {
layer.msg(str, { time: _time * 1000, offset: 'auto' }, function () { if (callBack != undefined) { callBack(); } });
} else if (icontype == "tips") {
layer.msg(str, { time: _time * 1000, offset: 'auto' }, function () { if (callBack != undefined) { callBack(); } });
} else if (icontype == "loading") {
layer.load(2, { time: _time * 1000 });
} else {
layer.msg(str, { time: _time * 1000, offset: 'auto' }, function () { if (callBack != undefined) { callBack(); } });
}
//if (icontype == "error") {
// layer.msg(str, { icon: 2, time: _time * 1000});
//} else if (icontype == "success") {
// layer.msg(str, { icon: 1, time: _time * 1000});
//} else if (icontype == "tips") {
// layer.msg(str, { icon: 0, time: _time * 1000});
//} else if (icontype == "loading") {
// layer.msg(str, { icon: 16, time: _time * 1000});
//} else {
// layer.msg(str, { time: _time * 1000});
//}
//setTimeout(function () {
// d = false;
// if (callBack != undefined) {
// callBack();
// }
//}, _time * 1000);
}
/**鎻愮ず 寮€鍙戜腑 */
function coding() {
tips("tips", "鍔熻兘寮€鍙戜腑,鏁璋呰В..", 3);
}
/**
* 鑾峰彇褰撳墠椤甸潰Url涓殑鍙傛暟鍊
* @param {string} propty 灞炴€у悕
* @param {any} defaultValue 榛樿鍊
* @param {string} url 鍙紶鍏rl,鎴栬€呬笉浼狅紝涓嶄紶鏃惰幏鍙栧綋鍓嶉〉
*/
function getUrlParameter(propty, defaultValue, url) {
if (url == null || url == undefined || url == "") {
url = window.location.href;
}
var loU = url.split("?");
if (loU.length > 1) {
var loallPm = loU[1].split("&");
for (var i = 0; i < loallPm.length; i++) {
var loPm = loallPm[i].split("=");
if (loPm[0] == propty) {
if (loPm.length > 1) {
return trim(loPm[1]);
} else {
return defaultValue;
}
}
}
} else if (propty.toLowerCase() == "id") {
var loU = url.split("/");
if (loU.length > 0) {
loU.reverse()
var lastUrl = loU[0];
lastUrl = replaceAll(lastUrl, ".html", "");
return lastUrl;
}
}
return defaultValue;
}
/**
* 鍒ゆ柇鎸囧畾鍊兼槸鍚﹀瓨鍦ㄦ寚瀹氱殑涓€缁存暟缁勪腑
* @param {any} str 闇€瑕佸垽鏂殑鍊
* @param {Array} array 涓€缁存暟缁
*/
function ExistStrInOneDimensionalArray(str, array) {
var exist = false;
for (var i = 0; i < array.length; i++) {
if (array[i] == str) {
exist = true;
break;
}
}
return exist;
}
/**
* 鍒ゆ柇鎸囧畾鍊兼槸鍚﹀瓨鍦ㄦ寚瀹氱殑浜岀淮鏁扮粍涓
* @param {any} str1 闇€瑕佸垽鏂殑鍊?
* @param {any} str2 闇€瑕佸垽鏂殑鍊?
* @param {Array} array 浜岀淮鏁扮粍
*/
function ExistStrInTwoDimensionalArray(str1, str2, array) {
var exist = false;
for (var i = 0; i < array.length; i++) {
if (array[i][0] == str1) {
if (array[i][1] == str2) {
exist = true;
break;
}
}
}
return exist;
}
/**
* 鍒ゆ柇鎸囧畾鍊兼槸鍚﹀瓨鍦ㄦ寚瀹氱殑浜岀淮鏁扮粍涓
* @param {any} str1 闇€瑕佸垽鏂殑鍊?
* @param {any} str2 闇€瑕佸垽鏂殑鍊?
* @param {any} str3 闇€瑕佸垽鏂殑鍊?
* @param {Array} array 涓夌淮鏁扮粍
*/
function ExistStrInThreeDimensionalArray(str1, str2, str3, array) {
var exist = false;
for (var i = 0; i < array.length; i++) {
if (array[i][0] == str1) {
if (array[i][1] == str2) {
if (array[i][2] == str3) {
exist = true;
break;
}
}
}
}
return exist;
}
/**
* 婊氬姩鍒版渶椤堕儴
* */
function goScrollTop() {
window.scrollBy(0, -200);
var sdelay = 0;
if (document.body.scrollTop > 0) {
sdelay = setTimeout('goTop()', 20);
}
}
/**
* 婊氬姩鍒版寚瀹氬厓绱犻《绔
* @param {String} obj 濡 #txtMobile 鎴 .strMobile
* @param {Int} moveHeight 渚垮疁楂樺害锛屽彲浼犲叆 璐熷€
*/
function goScroll(obj, moveHeight) {
/// 婊氬姩鍒版寚瀹歩d鐨勫厓绱犵殑椤堕儴
$("html,body").stop(true);
if (moveHeight == undefined) {
moveHeight = 0;
}
$("html,body").animate({ scrollTop: $(obj).offset().top + moveHeight }, 600);
}
/**
* 杩斿洖涓婁竴椤
* */
function goback() {
window.history.go(-1);
}
/**
* 杩斿洖涓婁竴椤靛苟鍒锋柊
* */
function gobackRefresh() {
window.location = document.referrer;
}
/**
* 浣跨敤鏌愬瓧绗︿覆鏇挎崲鏌愬瓧绗︿覆
* @param {String} content 闇€瑕佹浛鎹㈢殑鏂囧瓧娈
* @param {String} oldReplace 闇€瑕佹浛鎹㈢殑鏂囧瓧
* @param {String} newReplace 瑕佹浛鎹㈡垚鐨勬枃瀛
*/
function replaceAll(content, oldReplace, newReplace) {
if (content == undefined) {
return "";
}
if (content.indexOf(oldReplace) > -1) {
content = content.replace(oldReplace, newReplace);
content = replaceAll(content, oldReplace, newReplace);
}
return content;
}
/**
* 鏇挎崲鎸囧畾妯℃澘涓紝璇ュ璞$殑鍊
* @param {any} obj
* @param {any} item
* @param {any} strTemplate
*/
function replaceHtmlTemplate(obj, item, strTemplate) {
for (var key in obj) {
strTemplate = replaceAll(strTemplate, "{{" + item + key + "}}", obj[key]);
}
return strTemplate;
}
/**
* 灏嗘寚瀹氬瓧绗︿覆 鍘婚櫎澶村熬绌烘牸
* @param {String} content 鎸囧畾鐨勫瓧绗︿覆
*/
function trim(content) {
return content.replace(/^\s+|\s+$/gm, '');
}
/**
* 绉婚櫎鎸囧畾鐨勬湯灏惧瓧绗︿覆
* @param {any} content
* @param {any} str
*/
function trimEndString(content, str) {
var index = content.lastIndexOf(str);
if (index > -1) {
content = content.substring(0, index);
}
return content;
}
/**
* 鍒囨崲鍥惧舰楠岃瘉鐮侊紝鎸囧畾瀵硅薄鐨刢hildren
* @param {any} obj 鎸囧畾鐨勫璞 涓€鑸瑃his
* @param {any} codeurl 楠岃瘉鐮佽姹傚湴鍧€
*/
function toggleCode(obj, codeurl) {
$(obj).children("img").eq(0).attr("src", codeurl + "?time=" + Math.random());
return false;
}
/**
* 鍒囨崲楠岃瘉鐮侊紝鎸囧畾瀵硅薄鐨 prev
* @param {any} obj 鎸囧畾鐨勫璞 涓€鑸瑃his
* @param {any} codeurl 楠岃瘉鐮佽姹傚湴鍧€
*/
function togglePrevCode(obj, codeurl) {
$(obj).prev().attr("src", codeurl + "?time=" + Math.random());
return false;
}
/**
* 鍒囨崲楠岃瘉鐮侊紝鎸囧畾瀵硅薄鐨 next
* @param {any} obj 鎸囧畾鐨勫璞 涓€鑸瑃his
* @param {any} codeurl 楠岃瘉鐮佽姹傚湴鍧€
*/
function toggleNextCode(obj, codeurl) {
$(obj).next().attr("src", codeurl + "?time=" + Math.random());
return false;
}
/**
* 鍒囨崲楠岃瘉鐮侊紝鎸囧畾瀵硅薄
* @param {any} obj 鎸囧畾鐨勫璞 涓€鑸瑃his
* @param {any} codeurl 楠岃瘉鐮佽姹傚湴鍧€
*/
function toggleThisCode(obj, codeurl) {
$(obj).attr("src", codeurl + "?time=" + Math.random());
return false;
}
/**
* 鍒囨崲鎸囧畾瀵硅薄鐨勬煇class
* @param {any} obj 鎸囧畾鐨勫璞 涓€鑸瑃his
* @param {any} selClass 鍒囨崲鐨刢lass
*/
function toggleClass(obj, selClass) {
$(obj).toggleClass(selClass);
}
/**
* 鍒囨崲瀵嗙爜鏄剧ず妗嗙被鍨
* @param {any} obj 鎸囧畾鐨勫璞 涓€鑸瑃his
* @param {any} selClass
*/
function changePaswordType(obj, selClass) {
$(obj).toggleClass(selClass);
if ($(obj).prev().attr("type") == "password") {
$(obj).prev().attr("type", "text")
} else {
$(obj).prev().attr("type", "password")
}
}
/**
* 鐢ㄤ簬楠岃瘉琛ㄥ崟鍏冪礌涓殑鍊?鍚湁鏈€氳繃鍒欒繑鍥 false锛屽苟鎻愮ず
* @param {any} idOrClass 涓€鑸娇鐢 class
*/
function checkValidata(idOrClass) {
var flag = true;
for (var i = 0; i < $(idOrClass).length; i++) {
flag = tipsValidate($(idOrClass).eq(i));
if (!flag) {
break;
}
}
return flag;
}
/**
* 鐢ㄤ簬楠岃瘉鎸囧畾琛ㄥ崟鍏冪礌鐨勫€硷紝鏈€氳繃鍒欒繑鍥 false锛屽苟鎻愮ず
* @param {String} idOrClass 鍙娇鐢╥d 鎴 class 濡 #txtMobile 鎴 .strMobile
*/
function tipsValidate(idOrClass) {
var obj = $(idOrClass);
var value = obj.val();
if (value == undefined) {
tips("tips", "璇锋鏌ュ弬鏁?, 3);
return false;
}
if (obj.attr("placeholder") != undefined && obj.attr("placeholder") == value) {
value = "";
}
if (obj.attr("nullmsg") != undefined) {
if (trim(value).length <= 0) {
tips("tips", obj.attr("nullmsg"), 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
}
}
if (obj.attr("data-min") != undefined) {
var minValue = parseInt(obj.attr("data-min"));
value = parseInt(value);
if (isNaN(value)) {
value = 0;
}
if (value < minValue) {
if (obj.attr("errormsg") != undefined) {
tips("tips", obj.attr("errormsg"), 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
} else {
tips("tips", "杈撳叆鍊间笉寰楀皬浜? + minValue, 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
}
}
}
if (obj.attr("data-max") != undefined) {
var maxValue = parseInt(obj.attr("data-max"));
value = parseInt(value);
if (isNaN(value)) {
value = 0;
}
if (value > maxValue) {
if (obj.attr("errormsg") != undefined) {
tips("tips", obj.attr("errormsg"), 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
}
else {
tips("tips", "杈撳叆鍊间笉寰楀ぇ浜? + maxValue, 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
}
}
}
if (obj.attr("data-minlength") != undefined) {
var minlen = parseInt(obj.attr("data-minlength"));
if (value.length < minlen) {
if (obj.attr("errormsg") != undefined) {
tips("tips", obj.attr("errormsg"), 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
} else {
tips("tips", "杈撳叆鍐呭涓嶅緱灏戜簬" + minlen + "浣嶉暱搴?, 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
}
}
}
if (obj.attr("data-maxlength") != undefined) {
var maxlen = parseInt(obj.attr("data-maxlength"));
if (value.length > maxlen) {
if (obj.attr("errormsg") != undefined) {
tips("tips", obj.attr("errormsg"), 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
} else {
tips("tips", "杈撳叆鍐呭涓嶅緱瓒呰繃" + maxlen + "浣嶉暱搴?, 3);
obj.focus();
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
return false;
}
}
}
if (obj.attr("datatype") != undefined) {
var type = obj.attr("datatype");
var flag = true;
switch (type) {
case "m":
if (!checkMobile(value)) {
flag = false;
}
break;
case "idcard":
if (!new IdCardUtils(value).VerifyIDCard()) {
flag = false;
}
break;
case "num":
if (isNaN(value)) {
return false;
}
break;
default:
}
if (!flag) {
if (obj.attr("errormsg") != undefined) {
tips("tips", obj.attr("errormsg"), 3);
var t = obj.attr("type");
if (t.toLowerCase() === "hidden") {
goScroll(obj.parent())
}
}
obj.focus();
return false;
}
}
return true;
}
/**
* 鏄剧ず鎸囧畾鍐呭锛屾寚瀹氬楂樼殑鎻愮ず绐
* @param {String} objId 鎸囧畾鍐呭瀹瑰櫒鐨処D
* @param {any} width 绐椾綋瀹藉害 px
* @param {any} height 绐椾綋楂樺害 px
*/
function showWindow(objId, width, height) {
var box = '
' + $('#' + objId).html() + '
';
var tit = $('#' + objId).attr("title");
//var dialog = $.dialog({
// lock: true,
// min: false,
// max: false,
// resize: false,
// title: tit,
// content: box,
// width: width,
// height: height,
// ok: function () {
// },
// cancel: false
//});
//椤甸潰灞
layer.open({
title: tit,
type: 1,
skin: 'layui-layer-rim', //鍔犱笂杈规
area: [width, height], //瀹介珮
content: box
});
}
/**
* 楠岃瘉鎵嬫満鍙风爜
* @param {String} mobile 闇€瑕侀獙璇佺殑鏂囧瓧
*/
function checkMobile(mobile) {
/// 楠岃瘉鎵嬫満鍙风爜
var ismobi = /^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/.test(mobile);
if (ismobi && !isNaN(mobile) && mobile.length == 11) {
return true;
}
return false;
}
/**
* 楠岃瘉鏄惁姝f暣鏁
* @param {String} num 闇€瑕侀獙璇佺殑鏂囧瓧
*/
function checkInt(num) {
var reg = new RegExp("^[0-9]*$");
if (!reg.test(num)) {
return false;
} else {
return true;
}
}
/**
* 楠岃瘉鏄惁娴偣鍨 涓€浣嶆垨涓や綅姝e皬鏁
* @param {String} num 闇€瑕侀獙璇佺殑鏂囧瓧
*/
function checkFloat(num) {
var reg = new RegExp("^[1-9][0-9]+(.[0-9]{1,2})?$");
if (!reg.test(num)) {
return false;
} else {
return true;
}
}
/**
* 楠岃瘉鏄惁閭
* @param {String} email 闇€瑕侀獙璇佺殑鏂囧瓧
*/
function checkEmail(email) {
var reg = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
if (!reg.test(email)) {
return false;
} else {
return true;
}
}
/**
* 鍙厑璁歌緭鍏 鏁板瓧 锛岄€傜敤onkeyup涓
* @param {any} e
*/
function checkNumber(e) {
if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) { //FF
if (!((e.which >= 48 && e.which <= 57) || (e.which >= 96 && e.which <= 105) || (e.which == 8) || (e.which == 46)))
return false;
} else {
if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode == 8) || (event.keyCode == 46)))
event.returnValue = false;
}
}
/**
* 鍙厑璁歌緭鍏ユ暟瀛楋紝鍙厑璁歌緭鍏?浣嶅皬鏁 锛岄€傜敤onkeyup涓
* @param {any} obj 鍙紶this
*/
function clearNoNum(obj) {
var val = obj.value + '';
if (event.keyCode == 39 || event.keyCode == 37 || event.keyCode == 40 || event.keyCode == 16) {
return false;
}
val = val.replace(/[^\d.]/g, ""); //娓呴櫎鈥滄暟瀛椻€濆拰鈥?鈥濅互澶栫殑瀛楃
val = val.replace(/\.{2,}/g, "."); //鍙繚鐣欑涓€涓? 娓呴櫎澶氫綑鐨
val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//鍙兘杈撳叆涓や釜灏忔暟
if (val.indexOf(".") < 0 && val != "") {//浠ヤ笂宸茬粡杩囨护锛屾澶勬帶鍒剁殑鏄鏋滄病鏈夊皬鏁扮偣锛岄浣嶄笉鑳戒负绫讳技浜 01銆?2鐨勯噾棰
val = parseFloat(val);
}
val = val + '';
var v = val.split('.')[0];
if (v.length > 9) {
v = v.substring(0, 9);
if (val.indexOf('.') > -1) {
v = v + '.' + val.split('.')[1];
}
val = v;
}
if (obj.value != val) {
obj.value = val;
}
}
/**
* 娓呴櫎鎸囧畾瀛楃涓蹭腑鐨勯潪鏁板瓧锛屽彧淇濈暀2浣嶅皬鏁
* @param {String} val 鎸囧畾鐨勫瓧绗︿覆
*/
function clearNoNumber(val) {
val = val + "";
val = val.replace(/[^\d.]/g, ""); //娓呴櫎鈥滄暟瀛椻€濆拰鈥?鈥濅互澶栫殑瀛楃
val = val.replace(/\.{2,}/g, "."); //鍙繚鐣欑涓€涓? 娓呴櫎澶氫綑鐨
val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//鍙兘杈撳叆涓や釜灏忔暟
if (val.indexOf(".") < 0 && val != "") {//浠ヤ笂宸茬粡杩囨护锛屾澶勬帶鍒剁殑鏄鏋滄病鏈夊皬鏁扮偣锛岄浣嶄笉鑳戒负绫讳技浜 01銆?2鐨勯噾棰
val = parseFloat(val);
}
val = val + '';
var v = val.split('.')[0];
if (v.length > 9) {
v = v.substring(0, 9);
if (val.indexOf('.') > -1) {
v = v + '.' + val.split('.')[1];
}
val = v;
}
return val;
}
/**
* 鍙厑璁歌緭鍏ユ暟瀛楋紝鍙厑璁歌緭鍏?浣嶅皬鏁 锛岄€傜敤onkeyup涓
* @param {any} obj 鍙紶this
*/
function clearNoNum3(obj) {
var val = obj.value + '';
if (event.keyCode == 39 || event.keyCode == 37 || event.keyCode == 40 || event.keyCode == 16) {
return false;
}
val = val.replace(/[^\d.]/g, ""); //娓呴櫎鈥滄暟瀛椻€濆拰鈥?鈥濅互澶栫殑瀛楃
val = val.replace(/\.{2,}/g, "."); //鍙繚鐣欑涓€涓? 娓呴櫎澶氫綑鐨
val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
val = val.replace(/^(\-)*(\d+)\.(\d\d\d).*$/, '$1$2.$3');//鍙兘杈撳叆涓変釜灏忔暟
if (val.indexOf(".") < 0 && val != "") {//浠ヤ笂宸茬粡杩囨护锛屾澶勬帶鍒剁殑鏄鏋滄病鏈夊皬鏁扮偣锛岄浣嶄笉鑳戒负绫讳技浜 01銆?2鐨勯噾棰
val = parseFloat(val);
}
val = val + '';
var v = val.split('.')[0];
if (v.length > 9) {
v = v.substring(0, 9);
if (val.indexOf('.') > -1) {
v = v + '.' + val.split('.')[1];
}
val = v;
}
if (obj.value != val) {
obj.value = val;
}
}
/**
* 鍙厑璁歌緭鍏ユ暣鏁版暟瀛楋紝涓嶅彲杈撳叆灏忔暟 锛岄€傜敤onkeyup涓
* @param {any} obj 鍙紶this
*/
function clearNoInt(obj) {
var val = obj.value + '';
if (event.keyCode == 39 || event.keyCode == 37 || event.keyCode == 40 || event.keyCode == 16) {
return false;
}
val = val.replace(/[^\d]/g, ""); //娓呴櫎鈥滄暟瀛椻€濆拰鈥?鈥濅互澶栫殑瀛楃
while (val.length > 1 && val.indexOf("0") == 0) {
val = val.substring(1, val.length);
}
if (val.length > 9) {
val = val.substring(0, 9);
}
val = val + '';
if (obj.value != val) {
obj.value = val;
}
}
/**
* 琛ㄥ崟AJAX鎻愪氦灏佽(鍖呭惈楠岃瘉)
* @param {String} apiName 鎺ュ彛鍦板潃
* @param {String} formId 琛ㄥ崟鐨処d鍊
* @param {String} btnId 鎻愪氦鎸夐挳鐨処d鍊
* @param {String} urlId 闅愯棌鐨勮璺宠浆鐨勯摼鎺ュ湴鍧€鐨 Id鍊
* @param {String} imgId 鍥惧舰楠岃瘉鐮佺殑Id鍊硷紝涓嶅瓨鍦ㄤ紶绌轰覆
* @param {Function} beforeCallBack 鎻愪氦涔嬪墠鐨勫鐞嗗嚱鏁帮紝蹇呴』杩斿洖boolen锛宼rue鍒欑户缁彁浜わ紝false 鍒欎笉杩涜鎻愪氦
* @param {Function} successCallBack 鎴愬姛鏃剁殑鍥炶皟
* @param {Function} errorCallback 澶勭悊寮傚父鏃剁殑鍥炶皟
*/
function AjaxInitForm(apiName, formId, btnId, urlId, imgId, beforeCallBack, successCallBack, failCallBack, errorCallBack) {
var formObj = $('#' + formId);
var btnObj = $("#" + btnId);
var urlObj = $("#" + urlId);
var imgObj = $("#" + imgId);
btnObj.click(function () {
if (btnObj.prop("disabled")) {
return false;
}
var requestData = {};
var obj = $(formObj).serializeArray();
$.each(obj, function (i, v) {
//requestData[v.name] = v.value;
appendToJson(requestData, v.name, v.value, ",");
})
if (beforeCallBack != undefined) {
if (beforeCallBack(requestData) == false) {
return false;
}
}
btnObj.prop("disabled", true);
btnObj.val("鎻愪氦涓?..");
var request = new ClientBase();
request.SendApiData(apiName, requestData,
function (response) {
formResponse(response, requestData);
},
function (response,msg) {
btnObj.prop("disabled", false);
btnObj.val("鍐嶆鎻愪氦");
if (imgObj != undefined) {
imgObj.click();
}
if (failCallBack != undefined) {
failCallBack(response);
return;
}
tips("tips", msg, 3);
},
formError, true);
return false;
})
//琛ㄥ崟鎻愪氦鍚
function formResponse(data, requestData) {
btnObj.val("鎻愪氦鎴愬姛");
if (successCallBack != undefined) {
successCallBack(data, requestData);
return;
} else {
tips("success", data.msg, 3, function () {
if (data.url != undefined && data.url != "") {
window.location.href = data.url;
}
else if (urlObj.length > 0 && urlObj.val() != "") {
if (urlObj.val() == "referrer") {
window.location.href = document.referrer;
}
else {
window.location.href = urlObj.val();
}
} else {
window.location.reload();
}
});
}
}
//琛ㄥ崟鎻愪氦鍑洪敊
function formError(res) {
btnObj.prop("disabled", false);
btnObj.val("鍐嶆鎻愪氦");
if (imgObj != undefined) {
imgObj.click();
}
if (res.responseJSON != undefined) {
return;
}
if (errorCallBack != undefined) {
errorCallBack(res);
} else {
if (isDebug) {
tips("error", res.msg, 5);
}
}
}
}
/**
* 寮傛鑾峰彇灞€閮ㄩ〉闈
* @param {String} url 璇锋眰鍦板潃
* @param {String} divIdOrClass 闇€瑕佹嫾鎺ョ殑瀹瑰櫒鐨 Id鍊兼垨 Class
* @param {bool} isRef 鏄惁娓呯┖鍘熸暟鎹
* @param {Function} callBack 鎴愬姛鏃堕澶栧鐞嗙殑鍥炶皟锛屽彲涓簎ndefined
* @param {Function} nullcallBack 褰撹幏鍙栫殑鍐呭涓虹┖鏃惰Е鍙戠殑鍥炶皟鍑芥暟
*/
function AjaxGetHtml(url, divIdOrClass, isRef, callBack, nullcallBack) {
$.ajax({
type: "get",
url: url,
dataType: "html",
success: function (data) {
if (isRef) {
$(divIdOrClass).html(data);
} else {
$(divIdOrClass).append(data);
}
if (callBack != undefined) {
callBack();
}
if (trim(data) == "") {
if (nullcallBack != undefined) {
nullcallBack();
}
}
}
})
}
/*鎸夐挳閿佸畾*/
function lockBtn(v, str, cls) {
/// 閿佸畾鎸夐挳 鍙敮鎸乥utton
/// 鎸夐挳
/// 閿佸畾鍚庢寜閽枃鏈?/param>
if ($.trim(cls).length <= 0) {
cls = 'sel';
}
$(v).attr('disabled', true);
$(v).addClass(cls);
if ($.trim(str).length <= 0) {
$(v).val('楠岃瘉涓?..');
} else {
$(v).val(str);
}
}
function unLockBtn(v, str, cls) {
/// 瑙i攣鎸夐挳 鍙敮鎸乥utton
/// 鎸夐挳
/// 閿佸畾鍚庢寜閽枃鏈?/param>
if ($.trim(cls).length <= 0) {
cls = 'sel';
}
$(v).removeAttr('disabled');
$(v).removeClass(cls);
if ($.trim(str).length <= 0) {
str = "涓嬩竴姝?;
}
$(v).val(str);
}
function lockTimeBtn(v, wait, str, cls) {
//閿佸畾鎸夐挳涓€瀹氭椂闂
if ($.trim(str).length <= 0) {
str = "鑾峰彇";
}
//閿佸畾鎸夐挳
lockBtn(v, wait + "绉掑悗閲嶆柊鍙戦€?, cls);
sendTime(wait, v, str, cls);
}
function sendTime(wait, v, str, cls) {
//寮€濮嬪€掕鏃
if (wait == 0) {
unLockBtn(v, str, cls);//瑙i攣鎸夐挳
} else {
setTimeout(function () {
wait--;
$(v).val(wait + "绉掑悗閲嶆柊鍙戦€?);
sendTime(wait, v, str, cls);
}, 1000);
}
}
/*鏃ユ湡鍑芥暟*/
function DateTimeInit(_date) {
_date = _date.replace(/T/g, '聽').replace(/\.[\d]{3}Z/, '').replace(/(-)/g, '/')
if (_date.indexOf(".") > 0) _date = _date.slice(0, _date.indexOf("."))
var date = new Date(_date);
return date;
}
function formatTime(_date, _init) {
var year = formatNumber(_date.getFullYear());
var month = formatNumber(_date.getMonth() + 1);
var day = formatNumber(_date.getDate());
var hour = formatNumber(_date.getHours());
var minute = formatNumber(_date.getMinutes());
var second = formatNumber(_date.getSeconds());
var result = _init.replace('yyyy', year).replace('MM', month).replace('dd', day).replace('HH', hour).replace('mm', minute).replace('ss', second);
return result;
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}
function format(now, mask) {
var d = now;
var zeroize = function (value, length) {
if (!length) length = 2;
value = String(value);
for (var i = 0, zeros = ''; i < (length - value.length); i++) {
zeros += '0';
}
return zeros + value;
};
return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function ($0) {
switch ($0) {
case 'd': return d.getDate();
case 'dd': return zeroize(d.getDate());
case 'ddd': return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][d.getDay()];
case 'dddd': return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];
case 'M': return d.getMonth() + 1;
case 'MM': return zeroize(d.getMonth() + 1);
case 'MMM': return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
case 'MMMM': return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];
case 'yy': return String(d.getFullYear()).substr(2);
case 'yyyy': return d.getFullYear();
case 'h': return d.getHours() % 12 || 12;
case 'hh': return zeroize(d.getHours() % 12 || 12);
case 'H': return d.getHours();
case 'HH': return zeroize(d.getHours());
case 'm': return d.getMinutes();
case 'mm': return zeroize(d.getMinutes());
case 's': return d.getSeconds();
case 'ss': return zeroize(d.getSeconds());
case 'l': return zeroize(d.getMilliseconds(), 3);
case 'L': var m = d.getMilliseconds();
if (m > 99) m = Math.round(m / 10);
return zeroize(m);
case 'tt': return d.getHours() < 12 ? 'am' : 'pm';
case 'TT': return d.getHours() < 12 ? 'AM' : 'PM';
case 'Z': return d.toUTCString().match(/[A-Z]+$/);
// Return quoted strings with the surrounding quotes removed
default: return $0.substr(1, $0.length - 2);
}
});
};
/**鑾峰彇鏃堕棿鎴 */
function getTimeStamp() {
var timestamp = new Date().getTime();
return timestamp;
}
/**
* 鏁扮粍绫诲瀷鏁版嵁鐨勬墿灞曪紝鍒ゆ柇瀛樺湪浣嶇疆
* @param {any} val 鎸囧畾鐨勬暟鎹
*/
Array.prototype.indexOf = function (val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
/**
* 鏁扮粍绫诲瀷鏁版嵁鐨勬墿灞曪紝绉婚櫎鎸囧畾鍏冪礌
* @param {any} val 鎸囧畾鐨勬暟鎹
*/
Array.prototype.remove = function (val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
/**
* 鍚戞寚瀹氬璞′腑 娣诲姞鎴栦慨鏀瑰瓧娈碉紝鍊间负undefined鍒欏垹闄よ瀛楁
* @param {Object} data 鎸囧畾鐨勫璞
* @param {any} prop 瀛楁鍚
* @param {any} val 鍊硷紝鍙负undefined
*/
function addToJson(data, prop, val) {
// 濡傛灉 val 琚拷鐣
if (typeof val === "undefined") {
// 鍒犻櫎灞炴€
delete data[prop];
}
else {
// 娣诲姞 鎴 淇敼
data[prop] = val;
}
}
/**
* 鍚戞寚瀹氬璞′腑 娣诲姞鍊硷紝浠呭湪涓嶅瓨鍦ㄦ椂娣诲姞锛屽瓨鍦ㄦ椂涓嶄細淇敼鍘熷€硷紝鍊间负undefined鍒欏垹闄よ瀛楁
* @param {Object} data 鎸囧畾鐨勫璞
* @param {any} prop 瀛楁鍚
* @param {any} val 鍊硷紝鍙负undefined
* @param {any} operater 鍒嗗壊绗
*/
function appendToJson(data, prop, val, operater) {
// 濡傛灉 val 琚拷鐣
if (typeof val === "undefined") {
// 鍒犻櫎灞炴€
delete data[prop];
}
else {
if (data[prop] != undefined) {
data[prop] = data[prop] + operater + val;
} else {
data[prop] = val;
}
}
}
/**
* 缁欏璞 璁剧疆灞炴€у€
* @param {any} obj
* @param {any} propty
* @param {any} reusltObj
*/
function setObjectValue(obj, propty, reusltObj) {
if (obj[propty] != undefined) {
addToJson(reusltObj, propty, obj[propty]);
}
return reusltObj;
}
/**
* 浠庡璞′腑 鑾峰彇鍊硷紝鍙缃粯璁ゅ€
* @param {any} propty
* @param {any} obj
* @param {any} defaultValue
*/
function getObjectValue(propty, obj, defaultValue) {
if (obj == undefined) {
if (defaultValue == undefined) {
return "";
}
return defaultValue;
} else {
if (obj.propty == undefined) {
if (defaultValue == undefined) {
return "";
}
return defaultValue;
} else {
return obj[propty];
}
}
}
/**
* 鑾峰彇 鎸囧畾鍏冪礌瀵硅薄鐨勫€
* @param {any} obj 鍙互涓篒D锛屾垨class 锛屽 #txtMobile 鎴 .strMobile
*/
function getDomValue(obj) {
if (IEBrowserVersion() < 10) {
if ($(obj).attr("placeholder") != undefined) {
if ($(obj).val() == $(obj).attr("placeholder")) {
return "";
}
}
}
return trim($(obj).val());
}
/**
* 绛夋瘮渚嬬缉鏀惧浘鐗囧ぇ灏
* @param {any} ImgD 鍥惧舰鐨刣om瀵硅薄
* @param {any} iwidth 瑕佺缉鏀剧殑瀹
* @param {any} iheight 瑕佺缉鏀剧殑楂
*/
function DrawImage(ImgD, iwidth, iheight) {
//鍙傛暟(鍥剧墖,鍏佽鐨勫搴?鍏佽鐨勯珮搴?
var image = new Image();
image.src = ImgD.src;
if (image.width > 0 && image.height > 0) {
if (image.width / image.height >= iwidth / iheight) {
if (image.width > iwidth) {
ImgD.width = iwidth;
ImgD.height = (image.height * iwidth) / image.width;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
} else {
if (image.height > iheight) {
ImgD.height = iheight;
ImgD.width = (image.width * iheight) / image.height;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
}
}
}
/**
* @param {string} img 鍥剧墖鐨刡ase64
* @param {int} dir exif鑾峰彇鐨勬柟鍚戜俊鎭
* @param {function} next 鍥炶皟鏂规硶锛岃繑鍥炴牎姝f柟鍚戝悗鐨刡ase64
*/
function getImgData(img, dir, next) {
var image = new Image();
image.onload = function () {
var degree = 0, drawWidth, drawHeight, width, height;
drawWidth = this.naturalWidth;
drawHeight = this.naturalHeight;
//浠ヤ笅鏀瑰彉涓€涓嬪浘鐗囧ぇ灏
var maxSide = Math.max(drawWidth, drawHeight);
if (maxSide > 3000) {
var minSide = Math.min(drawWidth, drawHeight);
minSide = minSide / maxSide * 3000;
maxSide = 3000;
if (drawWidth > drawHeight) {
drawWidth = maxSide;
drawHeight = minSide;
} else {
drawWidth = minSide;
drawHeight = maxSide;
}
}
var canvas = document.createElement('canvas');
canvas.width = width = drawWidth;
canvas.height = height = drawHeight;
var context = canvas.getContext('2d');
//鍒ゆ柇鍥剧墖鏂瑰悜锛岄噸缃甤anvas澶у皬锛岀‘瀹氭棆杞搴︼紝iphone榛樿鐨勬槸home閿湪鍙虫柟鐨勬í灞忔媿鎽勬柟寮
switch (dir) {
//iphone妯睆鎷嶆憚锛屾鏃秇ome閿湪宸︿晶
case 3:
degree = 180;
drawWidth = -width;
drawHeight = -height;
break;
//iphone绔栧睆鎷嶆憚锛屾鏃秇ome閿湪涓嬫柟(姝e父鎷挎墜鏈虹殑鏂瑰悜)
case 6:
canvas.width = height;
canvas.height = width;
degree = 90;
drawWidth = width;
drawHeight = -height;
break;
//iphone绔栧睆鎷嶆憚锛屾鏃秇ome閿湪涓婃柟
case 8:
canvas.width = height;
canvas.height = width;
degree = 270;
drawWidth = -width;
drawHeight = height;
break;
}
//浣跨敤canvas鏃嬭浆鏍℃
context.rotate(degree * Math.PI / 180);
context.drawImage(this, 0, 0, drawWidth, drawHeight);
//杩斿洖鏍℃鍥剧墖
next(canvas.toDataURL(img.split(';')[0].replace('data:', ''), 0.95));
}
image.src = img;
}
/**
* 灏嗕互base64鐨勫浘鐗噓rl鏁版嵁杞崲涓築lob
* @param {any} urlData 鐢╱rl鏂瑰紡琛ㄧず鐨刡ase64鍥剧墖鏁版嵁
*/
function convertBase64UrlToBlob(urlData) {
var arr = urlData.split(',');
var bytes = window.atob(arr[1]); //鍘绘帀url鐨勫ご锛屽苟杞崲涓篵yte
var mime = arr[0].match(/:(.*?);/)[1];// 缁撴灉锛 image/png
//澶勭悊寮傚父,灏哸scii鐮佸皬浜?鐨勮浆鎹负澶т簬0
var u8arr = new ArrayBuffer(bytes.length);
var ia = new Uint8Array(u8arr);
for (var i = 0; i < bytes.length; i++) {
ia[i] = bytes.charCodeAt(i);
}
return new Blob([u8arr], { type: mime });
}
/**
* 锛侊紒锛両E涓嶆敮鎸 灏嗕互base64鐨勫浘鐗噓rl鏁版嵁杞崲涓篎ile
* @param {any} urlData 鐢╱rl鏂瑰紡琛ㄧず鐨刡ase64鍥剧墖鏁版嵁
* @param {any} filename 鏂囦欢鍚
*/
function convertBase64UrlToFile(urlData, filename) {
var arr = urlData.split(',');
var bytes = window.atob(arr[1]); //鍘绘帀url鐨勫ご锛屽苟杞崲涓篵yte
var mime = arr[0].match(/:(.*?);/)[1];// 缁撴灉锛 image/png
//澶勭悊寮傚父,灏哸scii鐮佸皬浜?鐨勮浆鎹负澶т簬0
var u8arr = new ArrayBuffer(bytes.length);
var ia = new Uint8Array(u8arr);
for (var i = 0; i < bytes.length; i++) {
ia[i] = bytes.charCodeAt(i);
}
return new File([u8arr], filename, { type: mime });
}
/**
* 杈撳嚭鏃ュ織
* @param {any} str
*/
function debugLog(str) {
if (isDebug) {
if ((typeof str) == "object") {
console.log(str);
} else {
console.log(JSON.stringify(str));
}
}
}
/*
================ 寤舵椂鍔犺浇鍥剧墖 ==============
*/
/**
* 寤舵椂鍔犺浇鍥剧墖锛屼緥濡 fun_loadImgSrc('#id'); 鎴栬€ fun_loadImgSrc('body');
* @param {any} divobj
*/
function fun_loadImgSrc(divobj) {
var domain = document.location.host;
$(divobj).find('img').each(function () {
var imgobj = $(this);
var src = imgobj.attr('src');
if (!!src && src.indexOf('css') > -1) {
var _src = imgobj.attr('_src');
if (_src != undefined && _src.length > 0 && _src.substring(_src.length - 1, 1) != '/') {
if (_src.indexOf('http') == -1) {
_src = 'http://' + domain + _src;
}
if (_src.indexOf('.jpg') > -1 || _src.indexOf('.png') > -1 || _src.indexOf('.gif') > -1 || _src.indexOf('.jpeg') > -1 || _src.indexOf('.bmp') > -1 || _src.indexOf('http') > -1) {
var img = new Image();
$(img).attr('src', _src);
img.onload = function () {
imgobj.attr('src', _src);
};
}
}
}
});
}
/*瀛楀吀 Dictionary绫?/
var Dictionary = function () {
this.add = add;
this.datastore = new Array();
this.find = find;
this.remove = remove;
this.showAll = showAll;
this.count = count;
this.clear = clear;
this.toKVString = toKVString;
function add(key, value) {
this.datastore[key] = value;
}
function find(key) {
return this.datastore[key];
}
function remove(key) {
delete this.datastore[key];
}
function showAll() {
var str = "";
for (var key in this.datastore) {
str += key + " -> " + this.datastore[key] + "; "
}
console.log(str);
}
function count() {
var n = 0;
for (var key in Object.keys(this.datastore)) {
++n;
}
console.log(n);
return n;
}
function clear() {
for (var key in this.datastore) {
delete this.datastore[key];
}
}
function toKVString(isPrintOutEmpty, oparete) {
var content = "";
for (var key in this.datastore) {
if (key == "remove" || key == "indexOf") {
continue;
}
var value = this.datastore[key];
if (!isPrintOutEmpty) {
if (value == undefined || value == "") {
continue;
}
}
content += (key + "=" + value + oparete);
}
content = trimEndString(content, oparete);
return content;
}
}
var StorageHelper = function () {
this.setLocalStorage = function (key, value, expireMinute) {
if (this.checkStorageSurpport("local")) {
if (!(!!expireMinute)) {
expireMinute = 2000;
}
var expireTime = new Date().getTime() + 1000 * 60 * expireMinute;//鑾峰彇褰撳墠鏃堕棿
var json = JSON.stringify({ val: value, time: expireTime });
localStorage.setItem(key, json);
}
}
this.getLocalStorage = function (key) {
if (this.checkStorageSurpport("local")) {
var value = localStorage.getItem(key);//鑾峰彇瀛樺偍鐨勫厓绱
if (value == undefined) {
//debugLog(key + "宸茶繃鏈?);
return undefined;
}
var dataobj = JSON.parse(value);//瑙f瀽鍑簀son瀵硅薄
if (new Date().getTime() > dataobj.time) {
//debugLog(key + "宸茶繃鏈?);
this.removeLocalStorage(key);
return undefined;
} else {
return dataobj.val;
}
}
}
this.removeLocalStorage = function (key) {
if (this.checkStorageSurpport("local")) {
localStorage.removeItem(key);
}
return true;
}
this.clearLocalStorage = function () {
if (this.checkStorageSurpport("local")) {
localStorage.clear();
}
return true;
}
this.setSessionStorage = function (key, value, expireMinute) {
this.setLocalStorage(key, value, expireMinute);
//if (this.checkStorageSurpport("session")) {
// if (!(!!expireMinute)) {
// expireMinute = 2000;
// }
// var expireTime = new Date().getTime() + 1000 * 60 * expireMinute;//鑾峰彇褰撳墠鏃堕棿
// var json = JSON.stringify({ val: value, time: expireTime });
// sessionStorage.setItem(key, json);
//}
}
this.getSessionSotrage = function (key) {
return this.getLocalStorage(key);
//if (this.checkStorageSurpport("session")) {
// var value = sessionStorage.getItem(key);//鑾峰彇瀛樺偍鐨勫厓绱
// if (value == undefined) {
// //debugLog(key + "宸茶繃鏈?);
// return undefined;
// }
// var dataobj = JSON.parse(value);//瑙f瀽鍑簀son瀵硅薄
// if (new Date().getTime() > dataobj.time) {
// //debugLog(key + "宸茶繃鏈?);
// this.removeSessionSotrage(key);
// return undefined;
// } else {
// return dataobj.val;
// }
//}
}
this.removeSessionSotrage = function (key) {
this.removeLocalStorage(key);
//if (this.checkStorageSurpport("session")) {
// sessionStorage.removeItem(key);
//}
return true;
}
this.clearSessionStorage = function () {
if (this.checkStorageSurpport("session")) {
sessionStorage.clear();
}
return true;
}
this.checkStorageSurpport = function (val) {
if (val == "local") {
if (window.localStorage) {
return true;
} else {
//window.location.href = "/Error/BrowserUpdgram";
return false;
}
} else if (val == "session") {
if (window.sessionStorage) {
return true;
} else {
//window.location.href = "/Error/BrowserUpdgram";
return false;
}
}
else {
//window.location.href = "/Error/BrowserUpdgram";
return false;
}
}
}
function changePageNumber(page) {
}
var PagerHelper = function (ptotalCount, ptotalNumber, pindex, psize, callback, pshowTotalCount, pshowPrevAndNext) {
var TotalCount = parseInt(ptotalCount);
var TotalPages = parseInt(ptotalNumber);
var PageSize = parseInt(psize);
var PageIndex = parseInt(pindex);
var CenterSize = 6;
var showTotalCount = pshowTotalCount || false;
var showPrevAndNext = pshowPrevAndNext || true;
changePageNumber = function (page) {
callback(page);
}
this.getMiddleStart = function () {
return parseInt(Math.floor(TotalPages * 1.0 / 2.0));
}
this.GetStartPageNumber = function () {
var firstNum = PageIndex - (CenterSize / 2); //涓棿寮€濮嬬殑椤电爜
if (PageIndex < CenterSize)
firstNum = 2;
return firstNum;
}
this.GetEndPageNumber = function () {
var lastNum = PageIndex + CenterSize - ((CenterSize / 2) + 1); //涓棿缁撴潫鐨勯〉鐮
if (lastNum >= TotalPages)
lastNum = TotalPages - 1;
return lastNum;
}
this.CreatPageBar = function () {
var html = "";
if (TotalCount <= 0) {
return html;
}
if (TotalCount <= PageSize) {
return html;
}
var index = 1;
html += "
";
if (showTotalCount) {
html += "鍏辨壘鍒? + TotalCount + "鏉狘/span>";
}
if (showPrevAndNext && PageIndex > 1) {
html += "涓婁竴椤袋/a>";
}
if (TotalPages <= 11) {
for (var i = 1; i <= TotalPages; i++) {
index++;
if (i == PageIndex) {
html += "" + i + "";
} else {
html += "" + i + "";
}
}
}
if (TotalPages > 11) {
//澶
for (var i = 1; i <= 1; i++) {
index++;
if (i == PageIndex) {
html += "" + i + "";
} else {
html += "" + i + "";
}
}
//涓棿閮ㄥ垎
var startPageNumber = this.GetStartPageNumber();
var endPageNumber = this.GetEndPageNumber();
if (PageIndex >= CenterSize) {
html += "...";
}
for (var i = startPageNumber; i <= endPageNumber; i++) {
if (PageIndex == i)
html += "" + i + " ";
else
html += "" + i + "";
}
if (TotalPages - PageIndex > CenterSize - ((CenterSize / 2))) {
html += "...";
}
//灏鹃儴
for (var i = TotalPages; i <= TotalPages; i++) {
index++;
if (i == PageIndex) {
html += "" + i + "";
} else {
html += "" + i + "";
}
}
}
if (showPrevAndNext && PageIndex < TotalPages) {
html += "涓嬩竴椤袋/a>";
}
html += "