Re: [問題] 多個下拉選單並存

看板Ajax作者 (艾瑞克)時間16年前 (2008/05/10 19:04), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
<body onload="getdef();"> <form id="form1" name="form1" method="post" action=""> <script type="text/JavaScript"> <!-- function surfto(obj){ var selt=document.getElementById(obj); window.open(selt.options[selt.selectedIndex].value,'_self',''); } function showInfo(obj){ alert(obj[obj.selectedIndex].getAttribute("text")); } function getdef(){ var s1=document.getElementById('select1'); var s2=document.getElementById('select2'); document.getElementById('ft1').innerHTML=''+s1[s2.selectedIndex].title; document.getElementById('ft2').innerHTML=''+s2[s2.selectedIndex].title; } //--> </script> <select name="select1" id="select1" onchange="document.getElementById('ft1'). innerHTML=''+this[this.selectedIndex].title;" > <option value="000.html" title="000" selected="selected">000</option> <option value="111.html" title="111">111</option> <option value="222.html" title="222">222</option> </select> <input type="button" value="GO" onClick="surfto('select1')"/></form> <span id="ft1"></span> <select name="select2" id="select2" onchange="document.getElementById('ft2'). innerHTML=''+this[this.selectedIndex].title;"> <option value="444.html" title="444" selected="selected">444</option> <option value="111.html" title="111">111</option> <option value="222.html" title="222">222</option> </select> <input type="button" value="GO" onClick="surfto('select2')"/> <span id="ft2"></span> </form> </body> ※ 引述《gpgpt (陌生)》之銘言: : 想請教如何在一個頁面當中出現多個下拉式選單? : 我目前是這樣寫:(沒有用到資料庫,只有連到該網頁) : <form id="form1" name="form1" method="post" action=""> : <script language="JavaScript"> : <!-- : function surfto(form) : {var myindex=form.select1.selectedIndex; : window.open(form.select1.options[myindex].value,'_self','');} : //--> : function showInfo(obj) : {alert(obj[obj.selectedIndex].getAttribute("text"));} : </script> : <select name="select1" id="form" onchange="document.getElementById('ft1'). : innerHTML=''+this[this.selectedIndex].title;"> : <option value="000.html" title="000" selected="selected">000</option> : <option value="111.html" title="111">111</option> : <option value="222.html" title="222">222</option> : </select> : <input type="button" value="GO" onClick="surfto(this.form)"/></form> : <span id="ft1"></span> : 可是只要複製第二個,就會打架,其中一個無法使用, : 就算改變select1為select2也沒有辦法, : 想請問還有哪邊需要改? : 還有一個問題是,我要讓他選擇後(還沒按GO)先顯示title的值, : 這部份是已經ok的,但一進入網頁時,他並不會先出現預設(000)的title, : 必須先選到111、222...才會出現, : 不知道該怎麼修改,讓他直接先出現selected的title? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.73.136.54

05/11 21:39, , 1F
成功哩~非常感謝唷~^^
05/11 21:39, 1F
文章代碼(AID): #189O4xcW (Ajax)
文章代碼(AID): #189O4xcW (Ajax)