JS怎么判断焦点是不是在textbox上

var el = window.event.srcElement;
if( el.id!= textbox.id ){
   //不是
}else{
  //是
}

<html>
<head>
</head>
<SCRIPT LANGUAGE='JavaScript'>
	
	var onblurMethod = new Array();
	
  function format() {
      alert("format");
  }
  
  function count() {
  	alert("count");	
  }
  
  function check() {
  	alert("check");
  	return true;
  }
  
</SCRIPT>
<SCRIPT LANGUAGE='JavaScript'>
function onloadCheck() {
		var target = document.forms[0];
		
		for(var i=0; i<target.elements.length; i++) {
			var e = target.elements[i];
			if(e.type == "text" || e.type == "password" || e.type == "file" || e.type == "textarea") {
	
				onblurMethod[e.name] = e.getAttribute("onblur");
				e.onblur="";
				
				e.attachEvent("onblur", onblurMethod[e.name]);
				e.attachEvent("onblur", check);
			}
		}
	}
</SCRIPT>
<body onload="onloadCheck()">
	<form name="test">
		name:<input type="text" name="name" value="" onblur="format();" /><br>
		age :<input type="text" name="age" value="" onblur="count();"/><br>
		<input type="button" name="btnOk" value="OK"/>
	</form>
</body>
</html>
 http://www.jb51.net/article/27684.htm

你可能感兴趣的:(text)