Incompatible jquery version upgrade: $ (& quot; input & quot;). attr (& quot; value & quot;) function changed, jquery. attr

Source: Internet
Author: User

Incompatible jquery version upgrade: $ ("input"). attr ("value") function changed, jquery. attr

The jquery-1.6.3.js was used in the previous project, and in this version, if we want to get the value of the input box, we can use $ ("input "). attr ("value") or $ ("input "). val (). These two methods are equivalent.

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

 


Recently another project team, using jquery-2.1.1.js, found the problem. I am using the IE 10 browser.

<Input type = "text" id = "speed" value = "45"/> $ ("# speed"). attr ("value"); // always 45

If the text control gives the default value, the result of using attr ("value") is always 45, and the actual input value of the input control is not obtained.

 

<Input type = "text" id = "speed"/> $ ("# speed"). attr ("value"); // always undefined

If the text control does not set the value attribute, the result obtained by using attr ("value") is always undefined.

 

After testing, whether it is version 1.6.3 or 2.1.1, the val () function can always be used to successfully obtain the actual value of the input box.

<Input type = "text" id = "speed" value = "45"/>$ ("# speed"). val (); // obtain the actual value of the input box.


 

I tried version 1.9.1 again and found that attr ("value") and val () are consistent with version 2.1.1. I don't know where jquery is changed. You need to pay attention to this issue when using jquery in the future. If you do not think of incompatibility issues caused by version upgrades, the problem may not be found. It can be seen that version upgrade is a very risky task and must be fully verified. It is best to have automated verification cases. If all test cases can pass, it basically means that the API functions of the version are compatible, and the risk after upgrade is relatively small. If you do not understand the version changes, you may be at a high risk.

 


How can I use jquery to change the value attr in input? The value text or html cannot be re-assigned @

$ ("# InputID"). val ("123123123 ");

Question about changing the input value in jquery table

$ (Function (){
$ ("Input. sure"). click (function (){
$ (This). val ("modify ");

$ (This). parent (). siblings (": eq (1)"). find ("input"). attr ("disabled", "disabled ");

});

});
This should be done. If it is not tested, the landlord will test it by himself.

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.