I had thought these two were the same, but they appear to not be. I've generally been using $obj.attr("value")
to work with form fields, but on the page I'm currently building, $obj.attr("value")
does not return the text I enter in my field. However, $obj.val()
does.
On a different page I've built, both $obj.attr("value")
and $obj.val()
return the text entered in the form field.
What could account for $obj.attr("value")
working as expected in one case but not in another?
What is the proper way to set and retrieve a form field's value using jQuery?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…