下面代码在输入错误数据时焦点未返回到输入栏,为什么呢?
<html>
<head>
<script type="text/javascript">
function check(obj){
if (/\d+/g.test(obj.value)){
return true;
}
else
{
alert("please into a number");
obj.focus();
return false;
}
}
</script>
</head>
<body>
<input type="text" name="data" id="data" value="" onBlur="check(this)">
</body>
</html>
<html>
<head>
<script type="text/javascript">
function check(obj){
if (/\d+/g.test(obj.value)){
return true;
}
else
{
alert("please into a number");
obj.focus();
return false;
}
}
</script>
</head>
<body>
<input type="text" name="data" id="data" value="" onBlur="check(this)">
</body>
</html>
onBlur="return check(this);">
在IE下可以,在firefox下不能,在firefox下怎么获得焦点呢?
window.setTimeout( function(){ obj.focus(); }, 0);
为什么呢