سؤال

I'm using jQuery Validation Plugin - v1.11.1 and jquery 1.10.2 but below code doesn't work in IE 8. It works fine in IE9 and above and also in other browsers like Chrome.

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script src="Scripts/jquery_validate.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btn').click(function() {                 
                $("#form1").validate({                       
                    rules: { 
                        <%= txt.UniqueID %>: "required"
                    },
                    messages: { 
                        <%= txt.UniqueID %>: "Please enter QTY"
                    }                                    
                });
            });
        });     
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    ID
    <asp:TextBox runat="server" ID="txt" ClientIDMode="Static" />
    <asp:Button Text="Test" runat="server" ID="btn" ClientIDMode="Static" />    
</asp:Content>

EDITED:

The reason I wrapped the validate() within $('#brn').Click(function(){}) event is that I have another postBack from GridView RowCommand Event.Is there another way to call jquery validate() only when the button is clicked?

هل كانت مفيدة؟

المحلول

Your code incorrectly wraps .validate() inside a click handler...

$('#btn').click(function() {                 
    $("#form1").validate({                       
        ...                             
    });
});

This is wrong because .validate() is only the initialization method of the plugin, so there is no reason to wrap it inside a click handler. The click of the submit button is already automatically captured and handled by the plugin.

This is the proper way to use the .validate() method...

$(document).ready(function() {

    $("#form1").validate({  // initialize the plugin                 
        // rules & options                          
    });

});

Working DEMO using jQuery 1.10.2 and jQuery Validate 1.11.1, tested with IE 81: http://jsfiddle.net/jsDzU/show

1 Tested with a real version of IE 8 installed in Windows XP SP3. Never assume that "IE 8 Mode" in another IE version is an accurate representation of the real thing or an "emulator" - it is not. Microsoft provides free VPC hard drive images for accurate testing in each IE version.

نصائح أخرى

Yes it works with "jquery-1.4.4.min.js"

you can test here

demo

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top