从下拉菜单中选择选项PASS后显示DIV [英] show DIV once selected option PASS from drop down menu
问题描述
我想创建简单的下拉选项,其中一个将是PASS然后显示DIV从下拉菜单中选择选项PASS,其他选项DIV将关闭
I would like to create simple drop down with options and one of the will be PASS then show DIV once selected option PASS from drop down menu, for other options DIV will be closed
<script type="text/javascript">
document.getElementById('mfi_4_a_i').onchange = function(){
if (this.value == 'PASS') {
document.getElementById('sdd').style.display = "block";
} else {
document.getELementById('sdd').style.display = "none";
}
};
</script>
<select id="test" name="test" onChange="changetextbox();">
<option value="PASS">PASS</option>
<option>No</option>
<option>No, but planning in future</option>
</select>
<input type="text" name="test" id="sdd" />
推荐答案
更改订单
<select id="test" name="test" onChange="changetextbox();">
<option value="PASS">PASS</option>
<option>No</option>
<option>No, but planning in future</option>
</select>
<input type="text" name="test" id="sdd" />
<script type="text/javascript">
document.getElementById('mfi_4_a_i').onchange = function(){
if (this.value == 'PASS') {
document.getElementById('sdd').style.display = "block";
} else {
document.getELementById('sdd').style.display = "none";
}
};
</script>
您需要确保在JavaScript运行时,DOM元素已准备好....
You need to ensure that when the JavaScript runs the DOM elements are ready ....
注意您的 id
属性也不匹配.. mfi_4_a_i
在JavaScript中与 test
在HTML中你应该写一个函数 changetextbox
或写 getElementById('blah')。onchange = function(){
不是两个......
Note your id
attributes do not match either ..mfi_4_a_i
in JavaScript vs test
in HTML and you should either write a function changetextbox
or write getElementById('blah').onchange = function() {
not both ...
<select id="test" name="test">
<option value="PASS">PASS</option>
<option>No</option>
<option>No, but planning in future</option>
</select>
<input type="text" name="test" id="sdd" />
<script type="text/javascript">
document.getElementById('test').onchange = function(){
if (this.value == 'PASS') {
document.getElementById('sdd').style.display = "block";
} else {
document.getElementById('sdd').style.display = "none";
}
};
</script>
另一个注意事项你有
document.getELementById('sdd').style.display = "none";
这应该是
document.getElementById('sdd').style.display = "none";
我改变了 L
的情况元素
这篇关于从下拉菜单中选择选项PASS后显示DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!