作者arrack (艾瑞克)
看板Ajax
标题Re: [问题] 多个下拉选单并存
时间Sat May 10 19:04:25 2008
<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
1F:推 gpgpt:成功哩~非常感谢唷~^^ 05/11 21:39