Home > Web Front-end > JS Tutorial > Prototype usage guide form.js_prototype

Prototype usage guide form.js_prototype

WBOY
Release: 2016-05-16 19:21:27
Original
1228 people have browsed it

This part provides many functions related to form operations, including the following parts. When an element is returned through the $ method, it can be called directly through $(element).method():

Form object: provides some methods to operate the entire form
Form.Element object: provides methods to operate a certain form element
TimedObserver class: periodic form monitor, when When the form element value changes, a callback function is executed. There are two types: Form and Element.
EventObserver class: Use events to monitor form elements. When the form element value changes, a callback function is executed. There are Form and Element Two types

Form object:

reset(form): form.reset()
serializeElements(elements): Serialize the elements in elements Serialization is to return the queryString form of all specified elements, which is convenient for use in xmlhttp or other places.
serialize(form): Serialize the entire form
getElements(form): Returns all serializable elements of the form
getInputs(form, typeName, name): Returns all input elements that match typeName and name
disable(form): makes the entire form unavailable
enable(form): makes the entire form available
findFirstElement(form): Returns the first available non-hidden element of type 'input', 'select', 'textarea'
focusFirstElement(form): Causes the element returned by findFirstElement(form) to be focused

Form.Element object:

focus(element) select(element): An encapsulation of the built-in methods of the html element, in addition to returning the element itself
serialize(element): Serialize the specified form element and return the key=value form. The returned string has been encodeURIComponent
getValue(element): Return the value of the element
clear(element): Clear the value of the element
present(element): Determine whether the value of the element is non-empty
activate(element): Give the element focus
disable(element): Make the element unavailable
enable(element): is an element available

$F = Form.Element.getValue Easy to use

Form.Element.Observer and Form.Observer classes:

Monitor form elements periodically. If the value of the form or form element changes, execute a callback function. The usage method is as follows:

var oser=new Form.Element.Observer(element, frequency, callback)
or oser=new Form.Observer(form, frequency, callback)
callback can define two parameters form/element, Form.serialize()/value

Form.Element.EventObserver and Form.EventObserver classes:

These two classes are similar to the above, except that instead of periodic monitoring, they use the element's change or click event to monitor changes in form elements. When changes occur, a callback is executed. The parameters are the same as above

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template