开发者

How to write the condition to check the validation using jquery or javascript

开发者 https://www.devze.com 2023-03-21 13:27 出处:网络
hello friends, $(\'input[name=checkedRecordsCat]\').attr(\'checked\', true); $(\'input[name=checkedRecordsSubCat]\').attr(\'checked\', true);

hello friends,

        $('input[name=checkedRecordsCat]').attr('checked', true);
        $('input[name=checkedRecordsSubCat]').attr('checked', true);
        $('input[na开发者_运维知识库me=checkedRecordsAtta]').attr('checked', true);
        $('input[name=checkedRecordsTextComp]').attr('checked', true);
        $('input[name=checkedRecordsVariableText]').attr('checked', true);
        $('input[name=checkedRecordsFreeFormText]').attr('checked', true);

I have this in my page. i need to check if non of them are checked I need to show a popup message. atleast one check box checked I need do return true.

how to write this condition using jquery or javascript

thanks


Assuming there are no other elements that have a name starting with checkedRecords you can use the starts-with selector combined with the :checked selector

if ( $('input[name^="checkedRecords"]:checked').length ){
   // at least one is checked
   return true;
} else {
   // none is checked
   // show popup here..
}
0

精彩评论

暂无评论...
验证码 换一张
取 消