Re: [問題] 多個下拉選單並存
<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
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
問題
1
3