I am trying to achieve the following with jQuery:
Select max 3 check boxes out of 20, w开发者_JAVA技巧hen three check boxes are selected run jQuery function.
If I understand correctly you want to run a function if three boxes are checked? To do that use
$(":checkbox").click(function(){
if($(":checkbox:checked").length==3))
//run function here
});
I'm considering the example on the official documentation of Jquery: http://api.jquery.com/checked-selector/
<script>
function myFunction(){
}
function countChecked() {
var n = $("input:checked").length;
if(n==3){
myFunction();
}
}
$(":checkbox").click(countChecked);
</script>
精彩评论