Home >Web Front-end >JS Tutorial >Summary of jquery's example of determining whether a check box is selected

Summary of jquery's example of determining whether a check box is selected

零下一度
零下一度Original
2017-06-28 11:30:371517browse

jquery Let’s summarize the problem of determining whether the check box is selected and how to select it.
Let’s get to the point, or when the page has the following set of check boxes:

Apple

Orange

Banana

Grape

Then use Jquery to get name=fruit The method of setting the value of a set of checkboxes is as follows:

var checkVal='';

$("input[name='fruit']:checkbox").each(function( ){

if($(this).attr('checked')){

checkVal+=$(this).val()+',';

}

})

Determine whether the check box of the name=fruit group has a selected option:

var flag=false;

$( "input[name='fruit']:checkbox").each(function(){

if($(this).attr('checked')){

flag=true ;

}

})

if(flag){

alert('has been selected');

}else {

alert('No option is selected');

}

The above is how jquery determines whether a check box is selected. I hope It will be helpful for everyone’s learning. You can also use js to obtain it. Please refer to "JS Determine Whether the Checkbox Is Selected Example"

The above is the detailed content of Summary of jquery's example of determining whether a check box is selected. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn