使用复选框帮助删除班级 [英] Help removing class with checkbox
本文介绍了使用复选框帮助删除班级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从选中的复选框中删除一个班级
I am trying to remove a class from a div with a checked checkbox
我的Jquery:
<script type="text/javascript">
// Submit form when checkbox is pressed
$(function() {
$('.menuitem input:checkbox').change(function(){
$('form').submit();
})
// Remove hidediv class from div - DOES NOT WORK
$('input:submit').hide().addClass("sdasd");
if($(this).is(":checked")) {
$('div.hidediv').removeClass("hidediv").show(slow);
} else {
$('div.hidediv').addClass("hidediv");
}
});
});
</script>
我的CSS:
.hidediv {display:none;}
我的HTML:
<form accept-charset="UTF-8" action="/" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div>
<div class="menuitem">
<label for="search_company1">company1</label>
<input name="search[company1_is_true]" type="hidden" value="0" /><input id="search_company1_is_true" name="search[company1_is_true]" type="checkbox" value="1" />
</div>
<div class="menuitem">
<label for="search_company3">company3</label>
<input name="search[company3_is_true]" type="hidden" value="0" /><input id="search_company3_is_true" name="search[company3_is_true]" type="checkbox" value="1" />
</div>
<div class="hidediv">
<div class="menuitem">
<label for="search_company2">company2</label>
<input name="search[company2_is_true]" type="hidden" value="0" /><input id="search_company2_is_true" name="search[company2_is_true]" type="checkbox" value="1" />
<div>
</div>
<input id="search_submit" name="commit" style="display:none;" type="submit" value="Submit" />
</form>
推荐答案
我认为问题在于您在按钮更改时提交了表单,却什么也没做:
I think that the problem is that you submit the form on the button change and do nothing else:
$('.menuitem input:checkbox').change(function() {
$('form').submit();
})
您应该这样做:
$('.menuitem input:checkbox').change(function(){
if($(this).is(":checked")) {
$('div.hidediv').removeClass("hidediv").show('slow');
}
});
如果您不希望上课,那么就没有必要像以前那样放置其他东西了,您不能再像以前那样使用类选择器了
Ther is no point in putting an else like you did before if you take off the class, you can't use the class selector anymore like you did
这篇关于使用复选框帮助删除班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文