【发布时间】:2013-11-22 17:48:05
【问题描述】:
我有一个包含 3 行复选框的表单。当且仅当仅在第一行中选中第三个复选框时,我才希望后两行可用。截至目前,我一直在显示所有三行,所以很可能我没有正确调用 JQuery。
此外,如果表格在隐藏/显示时自动缩放以考虑行的丢失/增加,那就太好了。这会自动发生吗(如果有影响,我正在使用 Bootstrap)。
代码如下:
JQuery
<body>
<script>
$(function showHide() {
$("name=checkboxes").click(function() {
if (($('.checkboxes-farms').prop('checked', true)) || $('.checkboxes-fields').prop('checked', true) || $('.checkboxes-cropzones').prop('checked', false)) {
$('#group2').hide();
$('#group3').hide();
}
});
});
</script>
</body>
HTML
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>Select Entities to Search For</legend>
<!-- Multiple Checkboxes (inline) -->
<div class="form-group" id="group1">
<label class="col-md-4 control-label" for="checkboxes">Table(s)</label>
<div class="col-md-4">
<label class="checkbox-inline" for="checkboxes-0">
<input type="checkbox" name="checkboxes" id="checkboxes-farms" value="1">
Farms
</label>
<label class="checkbox-inline" for="checkboxes-1">
<input type="checkbox" name="checkboxes" id="checkboxes-fields" value="3">
Fields
</label>
<label class="checkbox-inline" for="checkboxes-2">
<input type="checkbox" name="checkboxes" id="checkboxes-cropzones" value="5">
Cropzones
</label>
</div>
</div>
<!-- Multiple Radios (inline) -->
<div class="form-group" id="group2">
<label class="col-md-4 control-label" for="checkboxes">Cropyear</label>
<div class="col-md-4">
<label class="checkbox-inline" for="checkboxess-0">
<input type="checkbox" name="checkboxes-lower" id="checkboxes-cropyear" value="2014">
2014
</label>
</div>
</div>
<!-- Multiple Checkboxes (inline) -->
<div class="form-group" id="group3">
<label class="col-md-4 control-label" for="checkboxes">Crop</label>
<div class="col-md-4">
<label class="checkbox-inline" for="checkboxes-0">
<input type="checkbox" name="checkboxes-lower" id="checkboxes-corn" value="100">
Corn
</label>
<label class="checkbox-inline" for="checkboxes-1">
<input type="checkbox" name="checkboxes-lower" id="checkboxes-soybeans" value="200">
Soybeans
</label>
</div>
</div>
</fieldset>
</form>
【问题讨论】:
-
你能做jsbin.com的演示吗?
-
function showHide().. 你没有在任何地方调用过这个函数
-
$("name=checkboxes") whatttt???????????? :D
-
修复了一些错误。我希望你能从这里得到它jsfiddle.net/aamir/P4KKd :) 提示。始终在控制台中查找错误。看看fixingthesejquery.com/#slide1 ;)
标签: jquery html forms twitter-bootstrap