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.