开发者

jquery CheckBox required

开发者 https://www.devze.com 2022-12-10 20:37 出处:网络
how can I make a checkbox required ? my code aspx: <asp:CheckBox ID=\"cbIsAgree\" CssClass=\"{CheckedBox:true, messages:{CheckedBox:\'check me!.\'}}\" runat=\"server\" Text=\"check me!\" />

how can I make a checkbox required ?

my code

aspx:

<asp:CheckBox ID="cbIsAgree" CssClass="{CheckedBox:true, messages:{CheckedBox:'check me!.'}}" runat="server" Text="check me!" />

开发者_如何转开发javascript :

$.validator.addMethod("CheckedBox", function CheckedBox(value, element) {
        return $(element).is(':checked');
    }
    , 'check me!');

that code isnt working ... why ?


add required:true to the cssClass thing

e.g. in normal html

<input name="user" title="enter" class="{required:true,minlength:3}" />


I think you usage of the validator is wrong. All the addMethod function does is add a validation method. It does not bind that validation to the actual input for validation.

It is a two step process:

  • Define a method that says how an element should be validated
  • Create a list of rules that link an input to the relevant validation method

See the example on this page:

http://docs.jquery.com/Plugins/Validation/Methods/required


 $(document).ready(function() {
        $("#<%=cbIsAgree.ClientID %>").addClass("{required:true, messages:{required:'check me !.'}}");

    });

this will work cause .net puts the class in the span if you write something like this

<asp:chaeckbox runat="server" class=".....
0

精彩评论

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