Recently, I summarized the question about how to determine whether to select the check box in javascript. Because Jquery is used more recently, I also want to summarize the question about how to determine whether to select and how to select the check box in jquery.
Enter the subject, or when there is a set of check boxes on the page:
<Input type = "checkbox" name = "fruit" value = "apple"/> apple <input type = "checkbox" name = "fruit" value = "orange"/> orange <input type = "checkbox" name = "fruit" value = "banana"/> banana <input type = "checkbox" name = "fruit" value = "grape"/> grape
You can use Jquery to obtain the value of a set of check boxes with name = fruit as follows:
var checkVal='';$("input[name='fruit']:checkbox").each(function(){ if($(this).attr('checked')){checkVal+=$(this).val()+',';}})
Check whether the check box of name = fruit group has the selected option:
Var flag = false; $ ("input [name = 'fruit']: checkbox "). each (function () {if ($ (this ). attr ('checked') {flag = true ;}}) if (flag) {alert ('selected ');} else {alert ('no option selected ');}
Articles you may be interested in
- Javascript checks whether the check box is selected
- Jquery checks whether checkbox is selected
- Js determines whether the variable is a number
- Js to determine whether an array contains repeated values
- Js determines whether a value exists in a js Array
- How does js determine whether the scroll wheel is scroll down or up?
- Js checks whether the image is loaded and obtains the image width.
- Php determines whether the string is full of English, pure Chinese, and a combination of Chinese and English