我有下拉,我希望当用户从下拉列表中选择任何值时,然后在输入字段中设置光标的焦点。但这也适用于ipad。
<!DOCTYPE HTML>
<html lang = "en">
<head>
<title>formDemo.html</title>
<meta charset = "UTF-8" />
</head>
<body>
<h1>Form Demo</h1>
<form>
<legend>Selecting elements</legend>
<p>
<label>Select list</label>
<select id = "myList">
<option value = "1">one</option>
<option value = "2">two</option>
<option value = "3">three</option>
<option value = "4">four</option>
</select>
</p>
<input type="text" name="txt1" >
<form>
答案 0 :(得分:0)
试试这个
window.onload=function() {
document.getElemmentById("myList").onchange=function() {
document.getElementsByName("txt1")[0].focus();
}
}
在iOS或至少在移动版Safari中可能无法集中注意力,因为它会调出键盘,这不一定是用户想要的,因此Apple禁止使用脚本进行聚焦。 SetFocus does not work on iPad
答案 1 :(得分:0)
<select id = "myList" onchange="document.getElementsByName('txt1')[0].focus()">