如何通过选择显示/隐藏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
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>
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您的表单很大,您可以将它们放入单独的文件中,如下所示,
If your forms are large, you can put them in separate files like this,
像这样的东西吗?
Something like this?
只隐藏之前显示的 div 不是更好吗?
所以;
请注意,ID 不应以数字开头,但上面的内容应该可以。
Wouldn't it be better to only hide the previously shown div?
So;
Do note that IDs should not start with numbers, but the above should do it.
更好的版本:
Better version:
请注意,ID 不应以数字开头,但上面的内容应该可以。
Do note that IDs should not start with numbers, but the above should do it.