Issues with incompatible jquery version upgrades: $ ("input"). attr ("value") function changed

Source: Internet
Author: User

The previous project was using Jquery-1.6.3.js, which, in this version, can use $ ("input") if we want to get the value of the input box. attr ("value") or $ ("input"). Val (), these 2 methods are equivalent.

<input type= "text" id= "Speed"/>$ ("#speed"). attr ("value"); $ ("#speed"). Val ();


Recently to another project group, using Jquery-2.1.1.js, the results found the problem. I am using the IE10 browser.

<input type= "text" id= "Speed" value= "/>$" ("#speed"). attr ("value");//Always 45

If the text control gives the default value, the result of using attr ("value") is always 45, and will not get the value actually entered by the input control.

<input type= "text" id= "Speed"/>$ ("#speed"). attr ("value");//Always undefined

If the text control does not have the Value property set, the result obtained with attr ("value") is always undefined.

Tested, whether 1.6.3, or 2.1.1, using the Val () function, the actual value of the input box can always be obtained successfully.

<input type= "text" id= "Speed" value= "/>$" ("#speed"). Val ();//can get the actual value of the input box


I tried the 1.9.1 version and found that the performance of attr ("value") and Val () was consistent with the 2.1.1 version. I don't know where the version of jquery has changed, but you need to be aware of it later when you use jquery. If you don't think about incompatibilities with version upgrades, you may not be able to find the problem. This shows that the version upgrade is a very risky thing, must be fully validated, it is best to have automated verification use cases. If all the test cases pass, the basic implication is that the API features of the version are compatible and the risk is relatively small after the upgrade. If you do not understand the changes in the version, it is risky to upgrade.

Issues with incompatible jquery version upgrades: $ ("input"). attr ("value") function changed

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.