jquery gets a simple instance of the INPUT element value of form form _jquery

Source: Internet
Author: User

General method of value-taking

$ ("#id"). Val ();

$ ("#id"). attr ("value");

Where value is the Cifname attribute of the element's property name, such as <s:textfield id= "Cifname" key= "name=" Consbean.cifname "#request./>" Id,key,name. The value that is fetched is the character that corresponds to the double quotation mark after the attribute.

function Saveconsumervalidate () {
     var cifno =$ ("#cifNo"). Val ();//jquery Get text Box value Method 1
     var cardtype = $ ("#cardType" ). attr ("value"); jquery Get text Box value Method 2
     var Cardno = document.getElementById ("Cardno"). Value;//dom Get Value method

Val (), Val (val) method Atttr (name), Atttr (Key,value) method, and Value property

When you use $ ("#id") to get the input element of the page, $ ("#id") is found. Value cannot be fetched

$ ("#intro") is a jquery selector The result is the first element of id= "Intro" instead of the HTML DOM getElementById () method document.getelement

Value is a property of the HTML DOM text object that sets or returns the value of the text field's Values property.

Val () is the way jquery Gets or sets the DOM attribute of an element.

Val () Method: Gets the current value of the first matching element

Value: $ ("#id"). Val (); |$ ("element Elements"). Val ();

or $ ("#id") [0].value;

HTML code:
<input type= "text" value= "some text"/>
jQuery Code:
$ ("input"). Val ();

Val (val) method: Sets the value of each matching element.

Assignment: $ ("#id"). Val ("new value");

or $ ("#id") [0].value = "New value";

HTML code:
<input type= "text"/>
jQuery Code:
$ ("input"). val ("Hello world!");

attr (name) method: Gets the property value of the first matching element. This method makes it easy to get the value of a property from the first matching element. Returns undefined if the element does not have a corresponding property.

Value: $ ("#id"). attr ("value");

HTML code:

jQuery Code:
$ ("img"). attr ("src");
Result:
test.jpg

attr (Key,value) method: Sets a property value for all matching elements.

Assignment: $ ("#id"). attr (Attribute,value);

Description:
Sets the SRC attribute for all images.

HTML Code:
 

jQuery code:
$ ("img"). attr ("src", "test.jpg");
Results:
[, ]

The above jquery get form form INPUT element value Simple example is small series share to everyone's content, hope to give you a reference, also hope that we support cloud habitat community.

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.