[英]focus() not working for a select box(dropdown)
在某些特定事件上,我想专注于特定的选择框。 但
document.getElementById('myselect').focus()
不管用。 它适用于文本输入,但不适用于选择框。
你确定不是对焦?
我刚刚使用以下代码对 jsFiddle 进行了快速测试 - jsFiddle :
<select name="dropdown" id="dropdown">
<option value="1">One</option>
<option value="2">two</option>
</select>
<input type="text" id="textfield" /><br />
<button id="clickme"
onclick="javascript: document.getElementById('dropdown').focus()">
focus dropdown</button>
<button id="clickme1"
onclick="javascript: document.getElementById('textfield').focus()">
focus textfield</button>
Pressing the "Focus Dropdown" button does set the focus to the drop down field, but it doesn't actually appear to do anything. The dropdown field isn't highlighted, although if I press the arrow keys, different values will be selected.
它应该可以工作并且可以正常工作..检查小提琴
--html--
<select id="dpk">
<option> first </option>
<option> second </option>
<option> third </option>
</select>
<input type="button" value="focus Dropdown" id="btn" onclick="my_method()" />
--javascript--
function my_method()
{
document.getElementById('dpk').focus();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.