码迷,mamicode.com
首页 > Web开发 > 详细

JS控制文本框只能通過

时间:2014-12-17 16:17:55      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:ar   io   on   cti   ad   tt   new   res   br   

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()");

JS控制文本框只能通過

标签:ar   io   on   cti   ad   tt   new   res   br   

原文地址:http://www.cnblogs.com/Rambo-wu/p/4169445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!