number.onblur = function (){this.focus()};
经检测,ie是支持这种写法的,chrome不支持
以下可行
var number = document.getElementById("number");
window.onload = function(){
var pattern = /^[0-9]{6,16}$/;
number.onblur = function (){setTimeout("number.focus()",0)};
}
var number;
var pattern;
window.onload = function(){
number = document.getElementById("number");
pattern = /^[0-9]{6,16}$/;
}
number.onblur = function(){
if(pattern.test(number.value)){
number.style.backgroundColor = "white";
}
else{
number.style.backgroundColor = "pink";
number.focus();
}
}
你可以设置个hover属性,就会发现Hover属性会生效,但是光标无法定位。
我现在就是用setTimeout来处理的,过个一两遍毫秒后执行focus