Question about how jquery gets the input value

Source: Internet
Author: User

This article from: http://jeasony.iteye.com/blog/307684 I was just getting started with jquery and was unfamiliar with many things. When $ ("# ID") is used to obtain the page input element, it is found that $ ("# ID"). value cannot get the value.   Finally, with the help of the great Baidu, I found the cause of the problem: $ ("") Is a jquery object, not a DOM Element   Value is the attribute of Dom element.   Jquery corresponds to Val.   Val (): obtains the current value of the First Matching Element.

 Val (VAL): sets the value of each matching element.  

 So,CodeIt should be written as follows: Value: val = $ ("# ID") [0]. value;Assignment:$ ("# ID") [0]. value = "New Value ";
Or $ ("# ID"). Val ("New Value ");
 

Alternatively, you can: val = $ ("# ID"). ATTR ("value ");

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.