如何在onchange事件后某个文本框得到焦点?

来源:百度知道 编辑:UC知道 时间:2024/05/24 12:54:20
<script language="javascript">
function focus123()
{

document.getElementsByName("style").focus();

}
</script>

<select onChange="window.location.href=this.value;focus123()">
<option value="华美">华美</option>
<option value="阿哆诺斯">阿哆诺斯</option>
</select>

<input type="text" name="style" id="style" />

请拷贝以上页面试试 为什么我选了列表框里一个东西后 文本框style得不到焦点呢?
<script language="javascript">
function focus123()
{
var brand=getElementById("brand").value;
window.location.href="test.asp?brand="+brand;
document.getElementById("style").focus();

}
</script>

<select name="brand" id="brand" onChange="focus123()">

document.getElementsByName("style")[0].focus();
getElementsByName得到的是个集合,所以他不会有focus属性的,必须是里面的一个元素。
或者你用
document.getElementById("style").focus(); 也可以

哦 忘记了 补充下 window.location.href=this.value; 这句去掉不然就跳转了

document.getElementById("style").focus();