即在一行的几个项目中切换焦点不触发时间,在行之间切换时触发.
类似于每一行的<tr>有一个onblur时间.(<tr> 是没有onblur事件的)
[CODE]<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
var inTrY1 = 0;
var inTrY2 = 0;
var OnblurObj,Flag = false;
function getIE(objId)
{
var obj = document.getElementById(objId)
var top = obj.offsetTop;
var height = parseInt(obj.height);
while(obj=obj.offsetParent)
{
top += obj.offsetTop;
}
if((top < inTrY1 || top > inTrY2) && Flag){
if(confirm("确定要换行吗?")){
inTrY1 = top
inTrY2 = top + height;
return;
}else{
OnblurObj.focus();
}
}
}
function Onblur(obj){
OnblurObj = obj;
Flag = true;
}
function PageLoad(){
var obj = document.getElementById("tr1")
var top = obj.offsetTop;
var height = parseInt(obj.height);
while(obj=obj.offsetParent)
{
inTrY1 += obj.offsetTop;
}
inTrY2 = inTrY1 + height;
OnblurObj = document.getElementById('Text1')
OnblurObj.focus();
}
</script>
</head>
<body onload="PageLoad();">
<table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr id="tr1" height="30">
<td><input type="text" id="Text1" name="Text1" onfocus="getIE('tr1')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text2" name="Text2" onfocus="getIE('tr1')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text3" name="Text3" onfocus="getIE('tr1')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text4" name="Text4" onfocus="getIE('tr1')" onblur="Onblur(this)"/></td>
</tr>
<tr id="tr2" height="30">
<td><input type="text" id="Text5" name="Text5" onfocus="getIE('tr2')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text6" name="Text6" onfocus="getIE('tr2')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text7" name="Text7" onfocus="getIE('tr2')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text8" name="Text8" onfocus="getIE('tr2')" onblur="Onblur(this)"/></td>
</tr>
<tr id="tr3" height="30">
<td><input type="text" id="Text9" name="Text9" onfocus="getIE('tr3')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text10" name="Text10" onfocus="getIE('tr3')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text11" name="Text11" onfocus="getIE('tr3')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text12" name="Text13" onfocus="getIE('tr3')" onblur="Onblur(this)"/></td>
</tr>
<tr id="tr4" height="30">
<td><input type="text" id="Text13" name="Text13" onfocus="getIE('tr4')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text14" name="Text14" onfocus="getIE('tr4')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text15" name="Text15" onfocus="getIE('tr4')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text16" name="Text16" onfocus="getIE('tr4')" onblur="Onblur(this)"/></td>
</tr>
<tr id="tr5" height="30">
<td><input type="text" id="Text17" name="Text17" onfocus="getIE('tr5')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text18" name="Text18" onfocus="getIE('tr5')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text19" name="Text19" onfocus="getIE('tr5')" onblur="Onblur(this)"/></td>
<td><input type="text" id="Text20" name="Text20" onfocus="getIE('tr5')" onblur="Onblur(this)"/></td>
</tr>
</table>
</body>
</html>[/CODE]
[此贴子已经被作者于2007-3-28 14:16:28编辑过]