Home >Web Front-end >JS Tutorial >jQuery code to verify whether Checkbox is selected Recommended_jquery

jQuery code to verify whether Checkbox is selected Recommended_jquery

WBOY
WBOYOriginal
2016-05-16 18:02:331190browse

Most people probably think of this method when verifying:

Copy code The code is as follows:

function chk () //Verify whether it is selected return true, if not return false
{
var falg = 0;
$("input[name=cbname]:checkbox").each(function( ){
if($(this).attr("checked")) // Here you can use if($("#cr").is(":checked"))
{
falg =1; // You can add return false here to exit the loop
}
})
if(falg >0)
return true;
else
return false;
}

This method is really good, but I think the following code is simpler and more efficient:
if($("input[name=cbname]:checkbox").length==0 ) // None of the options are selected
Selected according to needs
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