求一个js控制input标签的显示和隐藏。。在线等

<select name="select" >
<option>北京</option>
<option>天津</option>
<option>上海</option>
<option >其他</option>
</select>
<input id='b' value='3253425'/>
<input id='a' />
根据上面的代码使我选择其他时就出现id=a的input标签,选择北京、天津、上海出现id=b的input标签,默认显示id=b的input标签

第1个回答  2013-02-26

不能发表,贴个图吧。该死的百度,说我内容有问题!切,鄙视


第2个回答  推荐于2017-09-13
使用jquery的写法:

<script type="text/javascript">
$(function(){)
$("select[name=select]").bind("change",function(){
if($(this).text()=="其他"){
$("#a").show();
$("#b").hide();
}else{
$("#a").hide();
$("#b").show();
}
});
});
</script>追问

额。。。不懂。。小白。。。能不能写清楚点?

追答



About

$(function(){
$("select[name=select]").bind("change",function(){
if($(this).val()=="其他"){
$("#a").show();
$("#b").hide();
}else{
$("#a").hide();
$("#b").show();
}
});
});

北京
天津
上海
其他

本回答被提问者采纳
第3个回答  2013-02-26
需要引入jquery吗,这个应该比较简单吧。js就可以控制啊。追问

额。。我就是要js控制啊。。

追答


function change(){
var valueObj = document.getElementById('selectID');
var AInput = document.getElementById('a');
var valueIndex = valueObj.selectedIndex;
var value = valueObj.options[valueIndex].value;
var text = valueObj.options[valueIndex].text;
//alert(value);
if(value==-1){
AInput.style.display = "block";
}else{
AInput.style.display = "none";
}
}

北京
天津
上海
其他

city:
other:

这个可以实现你说的,界面你自己调试,如果有问题,请留言。

追问

额、。。我需要2个input标签在同一个地方显示,也就是默认显示的是id=b的input标签,当我选择其他时就把id=b的input标签替换为id=a的input标签

相似回答