/全选取消按钮函数
function checkAll(chkobj) {
if ($(chkobj).text() == "全选") {
$(chkobj).children("span").text("取消");
$(".checkall input:enabled").prop("checked", true);
} else {
$(chkobj).children("span").text("全选");
$(".checkall input:enabled").prop("checked", false);
}
}
//===========================工具类函数============================
//只允许输入数字
function checkNumber(e) {
var keynum = window.event ? e.keyCode : e.which;
if ((48 <= keynum && keynum <= 57) || keynum == 8) {
return true;
} else {
return false;
}
}
//只允许输入小数
function checkForFloat(obj, e) {
var isOK = false;
var key = window.event ? e.keyCode : e.which;
if ((key > 95 && key < 106) || //小键盘上的0到9
(key > 47 && key < 60) || //大键盘上的0到9
(key == 110 && obj.value.indexOf(".") < 0) || //小键盘上的.而且以前没有输入.
(key == 190 && obj.value.indexOf(".") < 0) || //大键盘上的.而且以前没有输入.
key == 8 || key == 9 || key == 46 || key == 37 || key == 39) {
isOK = true;
} else {
if (window.event) { //IE
e.returnValue = false; //event.returnValue=false 效果相同.
} else { //Firefox
e.preventDefault();
}
}
return isOK;
}
//检查短信字数
function checktxt(obj, txtId) {
var txtCount = $(obj).val().length;
if (txtCount < 1) {
return false;
}
var smsLength = Math.ceil(txtCount / 62);
$("#" + txtId).html("您已输入<b>" + txtCount + "</b>个字符,将以<b>" + smsLength + "</b>条短信扣取费用。");
}
//四舍五入函数
function ForDight(Dight, How) {
Dight = Math.round(Dight * Math.pow(10, How)) / Math.pow(10, How);
return Dight;
}
//写Cookie
function addCookie(objName, objValue, objHours) {
var str = objName + "=" + escape(objValue);
if (objHours > 0) {//为0时不设定过期时间,浏览器关闭时cookie自动消失
var date = new Date();
var ms = objHours * 3600 * 1000;
date.setTime(date.getTime() + ms);
str += "; expires=" + date.toGMTString();
}
document.cookie = str;
}
//读Cookie
function getCookie(objName) {//获取指定名称的cookie的值
var arrStr = document.cookie.split("; ");
for (var i = 0; i < arrStr.length; i++) {
var temp = arrStr[i].split("=");
if (temp[0] == objName) return unescape(temp[1]);
}
return "";
}
//========================基于artdialog插件========================
//可以自动关闭的提示,基于artdialog插件
function jsprint(msgtitle, url, callback) {
var d = dialog({ content: msgtitle }).show();
setTimeout(function () {
d.close().remove();
}, 2000);
if (url == "back") {
frames["mainframe"].history.back(-1);
} else if (url != "") {
frames["mainframe"].location.href = url;
}
//执行回调函数
if (arguments.length == 3) {
callback();
}
}
//弹出一个Dialog窗口
function jsdialog(msgtitle, msgcontent, url, callback) {
var d = dialog({
title: msgtitle,
content: msgcontent,
okValue: '确定',
ok: function () { },
onclose: function () {
if (url == "back") {
history.back(-1);
} else if (url != "") {
location.href = url;
}
//执行回调函数
if (argnum == 5) {
callback();
}
}
}).showModal();
}
//打开一个最大化的Dialog
function ShowMaxDialog(tit, url) {
dialog({
title: tit,
url: url
}).showModal();
}
//执行回传函数
function ExePostBack(objId, objmsg) {
if ($(".checkall input:checked").size() < 1) {
parent.dialog({
title: '提示',
content: '对不起,请选中您要操作的记录!',
okValue: '确定',
ok: function () { }
}).showModal();
return false;
}
var msg = "删除记录后不可恢复,您确定吗?";
if (arguments.length == 2) {
msg = objmsg;
}
parent.dialog({
title: '提示',
content: msg,
okValue: '确定',
ok: function () {
__doPostBack(objId, '');
},
cancelValue: '取消',
cancel: function () { }
}).showModal();
return false;
}
//检查是否有选中再决定回传
function CheckPostBack(objId, objmsg) {
var msg = "对不起,请选中您要操作的记录!";
if (arguments.length == 2) {
msg = objmsg;
}
if ($(".checkall input:checked").size() < 1) {
parent.dialog({
title: '提示',
content: msg,
okValue: '确定',
ok: function () { }
}).showModal();
return false;
}
__doPostBack(objId, '');
return false;
}
//执行回传无复选框确认函数
function ExeNoCheckPostBack(objId, objmsg) {
var msg = "删除记录后不可恢复,您确定吗?";
if (arguments.length == 2) {
msg = objmsg;
}
parent.dialog({
title: '提示',
content: msg,
okValue: '确定',
ok: function () {
__doPostBack(objId, '');
},
cancelValue: '取消',
cancel: function () { }
}).showModal();
return false;
}
一些常用的JS方法
最新推荐文章于 2020-03-21 14:40:56 发布