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