使用单选按钮、下拉菜单和按钮显示选定的 div
a 有一个页面,其中包含:
<input type="radio" id="oqcline" class="section"/>OQC Line
<input type="radio" id="oqcbalance" class="section"/>Balance
<br/><br/>
Month
<select id="search_month" class="searchqp" name="search_month">
Year
<select id="search_year" class="searchqp" name="search_year">
<button id="search" type="button" class="ui-state-default ui-corner-all"><span>Search </span></button>
我有两个用于显示数据的 div
:
<div id="data">
<div id="list">
我想要这样:
if click "oqcline"-> select month and year ->click search->"data" can show,"list" hidden
if click "balanceline" -> select month and year ->click search->"list" can show,"data" hidden
你能告诉我如何做到这一点吗?
a have a page that consist of:
<input type="radio" id="oqcline" class="section"/>OQC Line
<input type="radio" id="oqcbalance" class="section"/>Balance
<br/><br/>
Month
<select id="search_month" class="searchqp" name="search_month">
Year
<select id="search_year" class="searchqp" name="search_year">
<button id="search" type="button" class="ui-state-default ui-corner-all"><span>Search </span></button>
and i have two div
s for show data:
<div id="data">
<div id="list">
i want like:
if click "oqcline"-> select month and year ->click search->"data" can show,"list" hidden
if click "balanceline" -> select month and year ->click search->"list" can show,"data" hidden
can you show me how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要清理 HTML - 使用
label
标签作为标签,并为单选按钮input
元素指定一个name 以便将它们分组在一起。
我们还将整个内容包装在一个
表单
中,因为它就是这样 - 一个搜索表单。现在,一个简单的 CSS 规则可以隐藏两个div
。如果您需要向没有 Javascript 的用户显示它们,您可能需要使用 Javascript 进行隐藏。最后是 jQuery。这将检查表单的提交并取消默认的浏览器操作,然后根据选择的单选按钮显示/隐藏正确的
div
看一下现场演示:http://jsfiddle.net/yijian/rEtxM/1
Well, first of all you'll want to clean up your HTML - use the
label
tag for labels, and give the radio buttoninput
elements aname
so that they'll be grouped together.We're also wrapping the whole thing in a
form
because that's what it is - a search form. Now, a simple CSS rule to hide the twodiv
. You might want to use Javascript to do the hiding instead if you need them to show for users without Javascript.Finally, the jQuery. This checks for the submission of the form and cancels the default browser action, before showing/hiding the correct
div
according to which of the radio button is selectedHave a look at the live demo: http://jsfiddle.net/yijiang/rEtxM/1