本文實例為大家分享了js點擊文本自動定位到下拉框選的具體代碼,供大家參考,具體內容如下
<html > <head runat="server"> <title></title> <style type="text/css"> #SiteStat { width: 97px; height: 181px; } </style> </head> <body> <from> <script language=javascript> function foo(){ //var i = 3; var i = document.getElementById("ds").value; o = document.getElementById("SiteStat"); for (c = 0; c < o.length; c++) { dy = o.options[c].value.indexOf(i) if(dy==0) //if (o.options[c].value == i) { o.options[c].selected = true; break; } } } </script> <select name="SiteStat" multiple="multiple" class="select1" id="SiteStat"> <option value="-1" selected></option> <option value="1" >狀態A</option> <option value="0">狀態B</option> <option value="22">狀態C</option> <option value="33">狀態D</option> </select> </from> <input type='text' name='olala' id='ds'/> <input type='submit' name='sub' value='查詢顯示' onclick="foo()"/> </body> </html>
以上就是本文的全部內容,希望對大家學習JavaScript程序設計有所幫助。