简体   繁体   中英

Trying to make some required fields in a checkbox with Jquery

I an working in a fiddle ( here ). In this, I need to have some mandatory fields checked before I perform any calculations. There are 6 mandatory fields, so I am trying to check to see that all 6 required inputs (whose TRs have their own class) are checked. I use $('tr.mustPass').find('input.subFieldCheck:checked').length to check this, but it does not seem to work. Whether or not this is six, my if statement says that it is not and sends out an alert stating this.

What am I doing wrong?

Thank you for your help.

Your JavaScript had a missing comma, and bracket. Also, lowered the specificity on your CSS selector slightly:

$('#calculate').on('click', function(event) {
   console.log($('tr.mustPass').find('input:checked').length)
});

That will log the number of checked required checkboxes to the console. ( Fiddle )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM