Day 83rd: Working with form forms in jquery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.