() The difference between the usage and value of val

Development, which often can not distinguish between the role and usage between the two, this subtotal, Changlaikankan:

 1. val () method for setting and getting values ​​of the form elements, for example: input, the value of the textarea. For jQuery object.

// to id = name of the element, the set value (value attribute is "John Doe") $ 
( " to the #NAME " ) .val ( " John Doe " ); 
 // get the value 
$ ( " to the #NAME " ) .val ( );

 

2. value the DOM object (html tag) of a property can be used to obtain, it can also be used provided:

= obj.value " to set obj value " ;     // no parentheses

 

3. Finally, the difference between js objects (DOM object) and jQuery object itself google. So the two can not be mixed up with.

Guess you like

Origin www.cnblogs.com/Archie2018/p/12106455.html