2
我正在使用jquery 1.9.1与alt复选框(http://alt-checkbox.starikovs.com/)来创建一个'好'复选框。我也想确保至少有一个复选框被选中,所以我使用jQuery验证插件。验证工作正常,但没有alt-checkbox样式,但是当我添加样式验证失败。jQuery复选框验证alt复选框
对复选框的(剥离下来)原始代码是:
<form id="form" name ="form">
<input type="checkbox" name="groups[]" class="checkbox" value="1">
<input type="checkbox" name="groups[]" class="checkbox" value="2">
</form>
而alt-复选框造型加入通过:
<script>
jQuery(".checkbox").altCheckbox({
});
</script>
和验证是通过完成:
$("#form").validate({
rules: {
'groups[]': {
required: true,
}
},
messages: {
'groups[]': "Please select at least one group"
}
});
});
</script>
替代复选框呈现:
<a href="#" class="alt-checkbox fontawesome-ok medium outline-unchecked"/>
<input type="checkbox" name="groups[]" id="groups[]" class="checkbox" value="1" style="display: none;"/>
<a href="#" class="alt-checkbox fontawesome-ok medium outline-unchecked checked"/>
<input type="checkbox" name="groups[]" id="groups[]" class="checkbox" value="2" style="display: none;"/>
我试过各种各样的东西让它工作,包括向第一个复选框添加validate =“required:true,minlength:2”,但没有运气。有什么建议么?
就像你可以看到altCheckbox隐藏标准的复选框,并把这个地方'anchor'验证插件适用于输入元素没有锚上。 – WooCaSh
作为@WooCaSh指向,你应该使用'if($('。alt-checkbox')。filter('。checked')。length == 0){return false; }' –
谢谢你。很有帮助。 – user2433891