如何通过选择显示/隐藏div(jquery)
问题描述:
我的代码:
my code:
<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并隐藏form2 + form3或$时显示div#form1 b $ b select option 2 show div#form2 and hide 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.