我正在处理一个表单并在 ie 中获取 null 或不是对象错误。
<form action="#" method="post" name="adv_search">
<input class="inputbox" type="text" name="keyword1" value="none" id="keyword1"/>
</form>
<script>
document.adv_search.keyword1.focus();
document.adv_search.keyword1.select();
</script>
//而如果我使用
<script>
var key1 = document.getElementById('keyword1');
key1.focus();
key1.select();
</script>
//一切安好
我想了解为什么。我希望它在没有输入字段的 id 标签的情况下工作
提前致谢
不应该 document.formname.fieldname.focus(); 和 document.formname.fieldname.select(); 工作?