manipulating form forms 1.
Attribute Manipulation
To set properties:
The first parameter indicates: The name of the property to set
The second parameter means: The value of the property name corresponds to
$ (selector). attr("title", "Preach Wisdom Podcast");
Get Properties:
parameter is: The name of the property to get, and the action returns the value corresponding to the specified property
$ (selector). attr("title");
This returns the value of the specified property
To remove a property:
parameter is: The name of the property to be removed
$ (selector). Removeattr("title");
Note: checked,selected,disabled you want to use The . Prop () method.
The prop method is often used to influence the dynamic state of DOM elements, rather than changing HTML properties. For example: the disabled attribute ofinput and button , and the checkbox the checked characteristics.
Detail Reference:http://api.jquery.com/prop/
2.
Value and content
Val () Method:
Function: Sets or returns the value of a form element, for example:input,select,textarea value
Gets the value of a matching element, matching only the first element
$ (selector). Val ();
Sets the value of all matching elements
$ (selector). Val("Specific value");
text () Method :
Function: Sets or gets the text content of a matching element
Get operation without parameters (note: This time the contents of all matching elements are stitched into a string, different from the other get operation!) )
$ (selector). Text ();
Set the action with parameters, which represent the text content to be set
If the contents of the setting contain HTML tags (<span> i want to create a span dynamically, is that OK?). </span>), the text method will output them as text content without creating elements. The main difference between this text () and the HTML () side
$ (selector). Text("I am content");
3. The difference between Val (), Text (), and HTML ()
1 <Script>2 $(function(){3 //Val ()4 Alert ($ ("input"). Val ());//Val (), gets the contents of the value in the label5 $("input"). Val("I was just assigned the input");6 //text ()7 Alert ($ ("Div"). Text ());//gets the text in a double-closed label that does not recognize the label8 $("Div"). Text("I'm just an assigned div.");9 //html ()Ten Alert ($ ("Div"). html ());//gets the text value in the double-closing label, identifying the label One $("Div"). html("<li> I am the HTML assignment </li>") A - }) - </Script>
Day 83rd: Working with form forms in jquery