简体   繁体   English

jQuery验证值的条件

[英]jquery validate condition on value

I would like to code a validation on button radio. 我想在按钮收音机上编写验证代码。 (yes or no). (是还是不是)。 Thanks. 谢谢。 my code : 我的代码:

conditions : {
    required : {
        depends: function(element) {
            if ($('#conditions')val('Yes').is(':checked')){
                return true;
            }else{
                return false;
            }
        }
    }
},

You probably want to return wether or not the radio with the value "Yes" is checked or not, and since ID's are unique, we'd assume that radio button has the ID #conditions 您可能想返回是否选择"Yes"值的单选按钮,并且由于ID是唯一的,因此我们假定单选按钮具有ID #conditions

conditions : {
    required : {
        depends: function(element) {
            return $('#conditions').is(':checked');
        }
    }
},

Give UniqueId to the YES radio button, and use the code below : 将UniqueId赋予YES单选按钮,并使用以下代码:

if ($('#uniqueid').prop("checked")) {
    return true;
} else {
    return false;
}

In Short : 简而言之 :

return $('#uniqueid').prop("checked")

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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