如何通过选择显示/隐藏 div.(jquery) [英] how to show/hide divs by select.(jquery)
本文介绍了如何通过选择显示/隐藏 div.(jquery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码:
<select id="select">
<option id="1" value="thai language">option one</option>
<option id="2" value="eng language">option two</option>
<option id="3" value="other language">option three</option>
</select>
<div id="form1">content here</div>
<div id="form2">content here</div>
<div id="form3">content here</div>
我想要的是在选择选项 1 时显示 div #form1 并隐藏 form2+form3,或者选择选项 2 显示 div#form2 并隐藏 form1+form2
what i want is to show div #form1 when select option 1 and hide form2+form3, or select option 2 show div#form2 and hide form1+form2
推荐答案
$('#select').change(function() {
$('#form1, #form2, #form3').hide();
$('#form' + $(this).find('option:selected').attr('id')).show();
});
请注意,ID 不应以数字开头,但应以上述方式开头.
Do note that IDs should not start with numbers, but the above should do it.
这篇关于如何通过选择显示/隐藏 div.(jquery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文