所以我想要做的是,在我选择第一个选项的那一刻,如果我选择第二个选项来重定向到另一个url,就会显示一个div。我甚至不知道这是否可能!示例:
<select class="required" id="thechoices">
<option value="">Service Type</option>
<option value="box1">From LAX Airport</option>
<option VALUE="http://www.dma.org/linuxsig/">To The Airport</option>
</select>
<div id="box1"><p>Box 1 stuff...</p></div>发布于 2011-10-11 06:46:04
<select id="options" onchange="optionCheck()">
<option></option>
<option value="show">Show Div</option>
<option value="goto">Go To Google</option>
</select>
<div id="hiddenDiv" style="height:100px;width:300px;border:1px;visibility:hidden;">
I am visible now!</div>
<script type="text/javascript">
function optionCheck(){
var option = document.getElementById("options").value;
if(option == "show"){
document.getElementById("hiddenDiv").style.visibility ="visible";
}
if(option == "goto"){
window.location = "http://google.com";
}
}
</script>您可以使用jquery使其更漂亮,但这应该可以工作。
发布于 2011-10-11 08:03:00
是的,这是可能的
将onchange事件处理程序添加到select。
<select class="required" id="thechoices" onchange="return airportChoice(this)">将您要隐藏的盒子ID的显示设置为隐藏。
#box1{display:none} //css这里是一个通用函数,它接收基于引用的参数,基于你的问题,所以你可以很容易地有很多从机场到机场的选择,如果你需要更多的选择,只需将以下内容添加到每个选择中。
onchange="return airportChoice(this)" JS函数
function airportChoice(n){
if(n.selectedIndex === 1){
// show a div (id) // alert(n.value);
document.getElementById(n.value).style.display = "block";
}else if(n.selectedIndex === 2){
location.href= n.value; // redirect the user to the url
}
// this last one is not what you ask but for completeness
// hide the box div if the first option is selected again
else if (n.selectedIndex == 0){ // alert(n[1].value);
document.getElementById(n[1].value).style.display = "none";
}
}https://stackoverflow.com/questions/7719367
复制相似问题