本文介绍了html中dropdownlist onchenge事件的javascript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮我在html中使用javascript在dropdownlist onchenge事件上显示div。
提前预计
Hi,
Can anybody help me to display div on dropdownlist onchenge event in html using javascript.
thanx in advance
推荐答案
<select id="dropdown1">
<option>Yes</option>
<option>No</option>
</select>
<div id="hiddenDiv">
This is a div, if "Yes" is selected, it's visible, if "No" is selected, it's not visible
</div>
<script type="text/javascript">
document.getElementById('dropdown1').onchange = function() {
var d = document.getElementById('dropdown1');
if (d.options[d.selectedIndex].text === "Yes") {
document.getElementById('hiddenDiv').style.display = 'block';
} else {
document.getElementById('hiddenDiv').style.display = 'none';
}
}
</script>
这篇关于html中dropdownlist onchenge事件的javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!