首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

jquery validate惯用选项

2013-08-01 
jquery validate常用选项)this.defaultShowErrors()}})The callback gets passed two arguments:?error

jquery validate常用选项
);this.defaultShowErrors();}});

The callback gets passed two arguments:

?

errorMapType: ObjectKey/value pairs, where the key refers to the name of an input field, values the message to be displayed for that input.errorListType: ArrayAn array for all currently validated elements. Contains objects with the following two properties:messageType: StringThe message to be displayed for an input.elementType: ElementThe DOMElement for this entry.errorPlacement (default: Places the error label after the invalid element)Type: Function()Customize placement of created error labels. First argument: The created error label as a jQuery object. Second argument: The invalid element as a jQuery object.

?

Example: Use a table layout for the form, placing error messags in the next cell after the input.

12345$("#myform").validate({errorPlacement: function(error, element) {error.appendTo( element.parent("td").next("td") );}});

The callback gets passed two arguments:

?

errorType: jQueryThe error label to insert into the DOM.elementType: jQueryThe validated input, for relative positioning.successType: String or Function()If specified, the error label is displayed to show a valid element. If a String is given, its added as a class to the label. If a Function is given, its called with the label (as a jQuery object) and the validated input (as a DOM element). The label can be used to add a text like “ok!”.

?

Example: Add a class “valid” to valid elements, styled via CSS.

1234$("#myform").validate({success: "valid",submitHandler: function() { alert("Submitted!") }});

Example: Add a class “valid” to valid elements, styled via CSS, and add the text “Ok!”.

123456$("#myform").validate({success: function(label) {label.addClass("valid").text("Ok!")},submitHandler: function() { alert("Submitted!") }});

The callback gets passed two arguments:

?

labelType: jQueryThe error label. Use to add a class or replace the text content.elementType: ElementThe element currently being validated, as a DOMElement.highlight (default: Adds errorClass (see the option) to the element)Type: Function()How to highlight invalid fields. Override to decide which fields and how to highlight.

?

Example: Highlights an invalid element by fading it out and in again.

1234567$(".selector").validate({highlight: function(element, errorClass) {$(element).fadeOut(function() {$(element).fadeIn();});}});

Example: Adds the error class to both the invalid element and it’s label

123456789101112$(".selector").validate({highlight: function(element, errorClass, validClass) {$(element).addClass(errorClass).removeClass(validClass);$(element.form).find("label[for=" + element.id + "]").addClass(errorClass);},unhighlight: function(element, errorClass, validClass) {$(element).removeClass(errorClass).addClass(validClass);$(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);}});

The callback gets passed three arguments:

?

elementType: ElementThe invalid DOM element, usually an input.errorClassType: StringCurrent value of the errorClass option.validClassType: StringCurrent value of the validClass option.unhighlight (default: Removes the errorClass)Type: Function()Called to revert changes made by option highlight, same arguments as highlight.ignoreTitle (default: false)Type: BooleanSet to skip reading messages from the title attribute, helps to avoid issues with Google Toolbar; default is false for compability, the message-from-title is likely to be completely removed in a future release.

?

Example: Configure the plugin to ignore title attributes on validated elements when looking for messages.

123$(".selector").validate({ignoreTitle: true});This method sets up event handlers for submit, focus, keyup, blur and click to trigger validation of the entire form or individual elements. Each one can be disabled, see the onxxx options (onsubmit, onfocusout, onkeyup, onclick). focusInvalid focuses elements when submitting a invalid form.

?

Use the debug option to ease setting up validation rules, it always prevents the default submit, even when script errors occur.

Use submitHandler to implement your own form submit, eg. via Ajax. Use invalidHandler to react when an invalid form is submitted.

Use rules and messages to specify which elements to validate, and how. See rules() for more details about specifying validation rules.

Use errorClass, errorElement, wrapper, errorLabelContainer, errorContainer, showErrors, success, errorPlacement, highlight, unhighlight, and ignoreTitle to control how invalid elements and error messages are displayed.

?

热点排行