日期:2014-05-16  浏览次数:20349 次

【转】js 数字验证 火狐 文本框获得焦点 文本框处于选中状态
http://chengxuyuanbiji.blog.163.com/blog/static/1824565062011444832369/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>实现代码预览效果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script>
function check(obj){
if(obj.value!=""){
  if(isNaN(obj.value)){  // isNaN -->is not a number 判断是不是数字 是返回true 不是返回false
   alert("请填写数字!");
   obj.focus();
   obj.select();
   window.setTimeout( function(){ obj.focus();obj.select(); }, 0);  //为了兼容火狐加的
  }
}
}
</script>

<input type="input"  onblur="check(this)"/>


</body>
</html>