下面写的为何就聚焦不到CompanyName输入框呢?
<div id="search-window" title="搜索" style="width: 600px; height: 300px; padding: 10px 20px;" onload="document.getElementById('CompanyName').focus()">
<div style="padding: 20px 20px 40px 40px;display:inline">
<form id="frmSearch" name="form">
<table class="tableForm datagrid-toolbar" style="width: 100%; height: 180px;">
<tr>
<th>公司名称:
</th>
<td>
<input name="CompanyName" id="CompanyName" style="width: 150px;" />
</td>
</tr>
<tr>
<th>部门名称:
</th>
<td>
<input name="DepartmentName" id="DepartmentName" style="width: 150px;" />
</td>
</tr>
<tr>
<th>存放位置:
</th>
<td>
<input name="Location" style="width: 150px;" />
</td>
</tr>
</table>
</form>
</div>
<div style="text-align: right; padding: 5px">
<a href="javascript:void(0)" onclick="SearchRecord()" class="easyui-linkbutton">查询</a>
<a href="javascript:void(0)" onclick="javascript:$('#search-window').window('close')" class="easyui-linkbutton">取消</a>
</div>
</div>JavaScript
<div id="search-window" title="搜索" style="width: 600px; height: 300px; padding: 10px 20px;" onload="document.getElementById('CompanyName').focus()">
<div style="padding: 20px 20px 40px 40px;display:inline">
<form id="frmSearch" name="form">
<table class="tableForm datagrid-toolbar" style="width: 100%; height: 180px;">
<tr>
<th>公司名称:
</th>
<td>
<input name="CompanyName" id="CompanyName" style="width: 150px;" />
</td>
</tr>
<tr>
<th>部门名称:
</th>
<td>
<input name="DepartmentName" id="DepartmentName" style="width: 150px;" />
</td>
</tr>
<tr>
<th>存放位置:
</th>
<td>
<input name="Location" style="width: 150px;" />
</td>
</tr>
</table>
</form>
</div>
<div style="text-align: right; padding: 5px">
<a href="javascript:void(0)" onclick="SearchRecord()" class="easyui-linkbutton">查询</a>
<a href="javascript:void(0)" onclick="javascript:$('#search-window').window('close')" class="easyui-linkbutton">取消</a>
</div>
</div>JavaScript
$(function(){
var $firstTxt=$("#CompanyName");
setTimeout(function() {
$firstTxt.focus();
}, 0);
return false;
});
});
//DOM方法
document.getElementById("CompanyName").focus(); //jquery方法
$("#CompanyName").focus();
}
...
</div>
<script type="text/javascript">
document.getElementById('CompanyName').focus()
</script>
window.onload = function () {
//DOM方法
document.getElementById("CompanyName").focus();
//jquery方法
$("#CompanyName").focus();
}
</script>
function test(){
//dom方法(建议不用)
document.getElementById("CompanyName").focus();
//jquery方法
$("#CompanyName").focus();
}
<body onload="document.getElementById('CompanyName').focus()">