2013-06-18 28 views
1

我已經下拉了,我希望當用戶從下拉列表中選擇任何值,然後在輸入字段中設置光標的焦點。但是這也應該在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

試試這個

window.onload=function() { 
    document.getElemmentById("myList").onchange=function() { 
    document.getElementsByName("txt1")[0].focus(); 
    } 
} 

的焦點很可能無法在iOS或至少在移動Safari瀏覽器,因爲它會彈出鍵盤,這是不一定是用戶希望蘋果禁用焦點使用腳本。 SetFocus does not work on iPad

+0

任何其他方式來完成這件事,我們可以使用任何其他功能 –

0
<select id = "myList" onchange="document.getElementsByName('txt1')[0].focus()"> 
+0

使用這個iPad上 –

+0

遺憾地告訴不起作用任何其他方式,但不存在「對焦」功能在Safari 5,其中是iPad的用途。 – Markipe

相關問題