I have a simple script in jQuery that works perfectly with jQuery 1.5.2 as you can see in this jsFiddle. What is supposed to happen is that when you bring focus to the text field, the default value is removed. And when if you leave the field blank, the original default value is put back in place.
http://jsfiddle.net/kHBsD/
However, the same exact code, where only jQuery 1.6.3 is used instead, is not working. (Not working means that the default value remains in the text box until you manually delete it as you can see in this jsFiddle.
http://jsfiddle.net/kHBsD/1/
There are no script errors in the console and other aspects of the function are operational. You can see the hover()
portion is working fine in both jsFiddles.
Summarized Version (the Root Problem)
jQuery 1.6.3 is returning undefined
for .attr('defaultValue')
.
jsFiddle using jQuery 1.6.3 (not working)
However, jQuery 1.5.2 is returning the expected value for .attr('defaultValue')
.
jsFiddle using jQuery 1.5.2 (working)
Question:
Does anyone know why this would be happening? (It looks like a jQuery bug to me.)
The following is still working...
document.getElementById().defaultValue
...but I think it's pretty ugly to have to do that where jQuery is available.
I'm open to other suggestions.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…