//计算区间的长度
function noemptyand(obj) {
// //只能输入8位
document.getElementById(obj).value = document.getElementById(obj).value.replace(/(^[.]?)|([^0-9.])/gi, "")
document.getElementById(obj).value = document.getElementById(obj).value.replace(/([^0-9.])/gi, "");
if (document.getElementById(obj).value.length > 8) {
document.getElementById(obj).value = document.getElementById(obj).value.substring(0, 8);
}
// //去多余的.
if (document.getElementById(obj).value.indexOf(".") > -1) {
var arr = document.getElementById(obj).value.split(".");
if (arr.length > 2) {
document.getElementById(obj).value = document.getElementById(obj).value.substring(0, document.getElementById(obj).value.lastIndexOf("."));
}
}
// //设空为零
if (document.getElementById(obj).value == "") {
document.getElementById(obj).value = "0";
}
document.getElementById("txtlength").value = parseFloat((parseFloat(document.getElementById("txtend").value) - parseFloat(document.getElementById("txtstart").value)).toFixed(3)).toString();
}
///只能输入0-9和.之间的数值
function checkPress(event) {
event = (event) ? event : window.event;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46) {
if (window.event) {
window.event.returnValue = false;
alert("请输入正确字符或数字");
} else {
event.preventDefault();
}
}
}
function checkPressCD(event) {
event = (event) ? event : window.event;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 48 || keyCode > 57) && keyCode != 8) {
if (window.event) {
window.event.returnValue = false;
alert("请输入正确字符或数字");
} else {
event.preventDefault();
}
}
}
function checkPress_new(event,v) {
event = (event) ? event : window.event;
var _v = document.getElementById(v);
var reg = /[u4E00-u9FA5]/g;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46) {
if (window.event) {
window.event.returnValue = false;
alert("请输入正确字符或数字");
} else {
if (!reg.test(_v.value)) {
event.preventDefault();
}
else {
alert("请输入正确字符或数字");
}
}
}
}
///只能输入数字和.之间的值0-5
function checkNums(event) {
event = (event) ? event : window.event;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 47 || keyCode > 53) && keyCode != 8 && keyCode != 46) {
if (window.event) {
window.event.returnValue = false;
alert("请输入正确字符或数字");
} else {
event.preventDefault();
}
}
}
///只能输入0-5和.之间的值
function check(event) {
event = (event) ? event : window.event;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 47 || keyCode > 53) && keyCode != 8 && keyCode != 46) {
if (window.event) {
window.event.returnValue = false;
} else {
event.preventDefault();
}
}
}
//判断输入的最大值,最大值只能是5,如果超过则重新输入,最小值是0,小于则重新输入
function checkTheLagerNum(id) {
if ((document.getElementById(id).value > 5) || (document.getElementById(id).value < 0)) {
document.getElementById(id).value = "";
return true;
} else {
return false;
}
}
///判断输入的前两位数值 如果是0111这种类型,则显示111,如果0.111则显示0.111
///如果是00111则显示111,如果是00.111则显示0.111
function CheckTheNumOneIS0(id) {
if ((document.getElementById(id).value).substr(0, 2) == "00" && (document.getElementById(id).value).substr(0, 3) != "00.") {
document.getElementById(id).value = document.getElementById(id).value.substr(2, (document.getElementById(id).value).length - 2);
} else if ((document.getElementById(id).value).substring(0, 1) == "0" && (document.getElementById(id).value).substring(0, 2) != "0." && (document.getElementById(id).value).length != 1) {
document.getElementById(id).value = document.getElementById(id).value.substring(1, (document.getElementById(id).value).length);
} else {
}
if ((document.getElementById(id).value).substr(0, 1) == ".") {
alert("请检查数据!!");
document.getElementById(id).value = "";
}
if (document.getElementById(id).value == "") {
document.getElementById(id).value = 0;
}
}
window.onload = function () {
checkPress(event), check(event);
}
///数组求最大数
function Listmax(numlist) {
var arr = numlist.split(',');
var maxnum = -1000000;
for (var i = 0; i < arr.length; i++) {
if (maxnum < parseInt(arr[i])) {
maxnum = arr[i];
}
}
return maxnum;
}
///JS保留两位小数
function changeTwoDecimal(x) {
var f_x = parseFloat(x);
if (isNaN(f_x)) {
//alert('function:changeTwoDecimal->parameter error');
return false;
}
f_x = Math.round(x * 100) / 100;
return f_x;
}
///js保留两位小数(强制)如果不足2位则补0,返回字符串格式
function changeTwoDecimal_f(x) {
var f_x = parseFloat(x);
if (isNaN(f_x)) {
//alert('function:changeTwoDecimal->parameter error');
return false;
}
var f_x = Math.round(x * 100) / 100;
var s_x = f_x.toString();
var pos_decimal = s_x.indexOf('.');
if (pos_decimal < 0) {
pos_decimal = s_x.length;
s_x += '.';
}
while (s_x.length <= pos_decimal + 2) {
s_x += '0';
}
return s_x;
}
///js获取页面传值
function getParameter(param) {
var query = window.location.search;
var iLen = param.length;
var iStart = query.indexOf(param);
if (iStart == -1)
{ return ""; }
//取得开始收索的位置
iStart += iLen + 1;
var iEnd = query.indexOf("&", iStart);
// 如果只有一个参数传进来
if (iEnd == -1)
{ return query.substring(iStart); }
else
{ return query.substring(iStart, iEnd); }
}
<input id="txtstart" οnkeyup="checkPress(event)" type="text" style ="ime-mode:disalbled"
runat="server" />
<input id="txtstart" οnkeyup="noemptyand(this.id)" type="text"
runat="server" />
function noemptyand(obj) {
// //只能输入8位
document.getElementById(obj).value = document.getElementById(obj).value.replace(/(^[.]?)|([^0-9.])/gi, "")
document.getElementById(obj).value = document.getElementById(obj).value.replace(/([^0-9.])/gi, "");
if (document.getElementById(obj).value.length > 8) {
document.getElementById(obj).value = document.getElementById(obj).value.substring(0, 8);
}
// //去多余的.
if (document.getElementById(obj).value.indexOf(".") > -1) {
var arr = document.getElementById(obj).value.split(".");
if (arr.length > 2) {
document.getElementById(obj).value = document.getElementById(obj).value.substring(0, document.getElementById(obj).value.lastIndexOf("."));
}
}
// //设空为零
if (document.getElementById(obj).value == "") {
document.getElementById(obj).value = "0";
}
document.getElementById("txtlength").value = parseFloat((parseFloat(document.getElementById("txtend").value) - parseFloat(document.getElementById("txtstart").value)).toFixed(3)).toString();
}
///只能输入0-9和.之间的数值
function checkPress(event) {
event = (event) ? event : window.event;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46) {
if (window.event) {
window.event.returnValue = false;
alert("请输入正确字符或数字");
} else {
event.preventDefault();
}
}
}
function checkPressCD(event) {
event = (event) ? event : window.event;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 48 || keyCode > 57) && keyCode != 8) {
if (window.event) {
window.event.returnValue = false;
alert("请输入正确字符或数字");
} else {
event.preventDefault();
}
}
}
function checkPress_new(event,v) {
event = (event) ? event : window.event;
var _v = document.getElementById(v);
var reg = /[u4E00-u9FA5]/g;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46) {
if (window.event) {
window.event.returnValue = false;
alert("请输入正确字符或数字");
} else {
if (!reg.test(_v.value)) {
event.preventDefault();
}
else {
alert("请输入正确字符或数字");
}
}
}
}
///只能输入数字和.之间的值0-5
function checkNums(event) {
event = (event) ? event : window.event;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 47 || keyCode > 53) && keyCode != 8 && keyCode != 46) {
if (window.event) {
window.event.returnValue = false;
alert("请输入正确字符或数字");
} else {
event.preventDefault();
}
}
}
///只能输入0-5和.之间的值
function check(event) {
event = (event) ? event : window.event;
keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode);
if ((keyCode < 47 || keyCode > 53) && keyCode != 8 && keyCode != 46) {
if (window.event) {
window.event.returnValue = false;
} else {
event.preventDefault();
}
}
}
//判断输入的最大值,最大值只能是5,如果超过则重新输入,最小值是0,小于则重新输入
function checkTheLagerNum(id) {
if ((document.getElementById(id).value > 5) || (document.getElementById(id).value < 0)) {
document.getElementById(id).value = "";
return true;
} else {
return false;
}
}
///判断输入的前两位数值 如果是0111这种类型,则显示111,如果0.111则显示0.111
///如果是00111则显示111,如果是00.111则显示0.111
function CheckTheNumOneIS0(id) {
if ((document.getElementById(id).value).substr(0, 2) == "00" && (document.getElementById(id).value).substr(0, 3) != "00.") {
document.getElementById(id).value = document.getElementById(id).value.substr(2, (document.getElementById(id).value).length - 2);
} else if ((document.getElementById(id).value).substring(0, 1) == "0" && (document.getElementById(id).value).substring(0, 2) != "0." && (document.getElementById(id).value).length != 1) {
document.getElementById(id).value = document.getElementById(id).value.substring(1, (document.getElementById(id).value).length);
} else {
}
if ((document.getElementById(id).value).substr(0, 1) == ".") {
alert("请检查数据!!");
document.getElementById(id).value = "";
}
if (document.getElementById(id).value == "") {
document.getElementById(id).value = 0;
}
}
window.onload = function () {
checkPress(event), check(event);
}
///数组求最大数
function Listmax(numlist) {
var arr = numlist.split(',');
var maxnum = -1000000;
for (var i = 0; i < arr.length; i++) {
if (maxnum < parseInt(arr[i])) {
maxnum = arr[i];
}
}
return maxnum;
}
///JS保留两位小数
function changeTwoDecimal(x) {
var f_x = parseFloat(x);
if (isNaN(f_x)) {
//alert('function:changeTwoDecimal->parameter error');
return false;
}
f_x = Math.round(x * 100) / 100;
return f_x;
}
///js保留两位小数(强制)如果不足2位则补0,返回字符串格式
function changeTwoDecimal_f(x) {
var f_x = parseFloat(x);
if (isNaN(f_x)) {
//alert('function:changeTwoDecimal->parameter error');
return false;
}
var f_x = Math.round(x * 100) / 100;
var s_x = f_x.toString();
var pos_decimal = s_x.indexOf('.');
if (pos_decimal < 0) {
pos_decimal = s_x.length;
s_x += '.';
}
while (s_x.length <= pos_decimal + 2) {
s_x += '0';
}
return s_x;
}
///js获取页面传值
function getParameter(param) {
var query = window.location.search;
var iLen = param.length;
var iStart = query.indexOf(param);
if (iStart == -1)
{ return ""; }
//取得开始收索的位置
iStart += iLen + 1;
var iEnd = query.indexOf("&", iStart);
// 如果只有一个参数传进来
if (iEnd == -1)
{ return query.substring(iStart); }
else
{ return query.substring(iStart, iEnd); }
}
ime-mode:disalbled :auto:active:inactive //禁止输入法中文切换
auto:不影响ime的状态。
active:指定所使用ime输入的字符。
inactive:指定所有不使用ime输入的字符
disabled:完全禁用ime
οnpaste="return false" //禁止粘帖
<input id="txtstart" οnkeyup="checkPress(event)" type="text" style ="ime-mode:disalbled"
runat="server" />
<input id="txtstart" οnkeyup="noemptyand(this.id)" type="text"
runat="server" />