67,513
社区成员
发帖
与我相关
我的任务
分享
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">
<head>
<title>Test</title>
</head>
<script>
function setFocus(){
var list=document.getElementsByTagName("input");
for(var i=0;i<list.length;i++){
if(!list[i].disabled&&list[i].parentNode.style.display!="none"&&list[i].parentNode.parentNode.style.display!="none"){
list[i].focus();
return;
}
}
}
</script>
<body onload="setFocus();">
<TABLE>
<TR style="display:none">
<TD><input type="text" id="aa" name="a1" value=""/></TD>
<TD><input type="text" id="bb" name="b1" value=""/></TD>
</TR>
<TR>
<TD><input type="text" id="cc" name="c1" value="" disabled="disabled"/></TD>
<TD><input type="text" id="dd" name="d1" value=""/></TD>
</TR>
</TABLE>
</body>
</html>
吃完饭来公布答案.
要不来看大牛的答案.
var inputArr = document.getElementByTagName('input');
inputArr[0].focus();
使用jquery更简单.
$('input').first().focus();