JS控制文本框只能通過

JS代碼:

var str_old = "";

var str_new = "";
var timerID;
var flag = true;

function ck(obj) {
alert(document.getElementById(obj).value);
}
function vv(obj) {
setInterval(function () { ck(obj); });
}
function check(obj) {
if (flag) {
str_old = document.getElementById(obj).value;
if (str_old != str_new) {
str_new = str_old;
str_old = document.getElementById(obj).value;
}
else {
document.getElementById(obj).value = "";
}
}
}

function txtFocus(obj) {
if (document.getElementById(obj).value != "") {
flag = false;
}
else {
flag = true;
}
timerID = setInterval(function () { check(obj); }, 35);
}
function txtChanged() {
flag = true;
}
function txtBlur() {
clearInterval(timerID);
}

function txtLeave(obj) {

if (event.keyCode == 13) {
obj.blur();
clearInterval(timerID);
}
}

後臺代碼:

this.txtFacilityID.Attributes.Add("onKeyPress", "txtLeave(this)");
this.txtFacilityID.Attributes.Add("onfocus", "txtFocus(‘txtFacilityID‘)");
this.txtFacilityID.Attributes.Add("onblur", "txtBlur()");
this.txtFacilityID.Attributes.Add("onpropertychange", "txtChanged()");

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。