I need to append some text to an input field...
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- React Native Inline style for multiple Text in sin
- Disable Browser onUnload on certain links?
There are two options. Ayman's approach is the most simple, but I would add one extra note to it. You should really cache jQuery selections, there is no reason to call
$("#input-field-id")
twice:The other option,
.val()
can also take a function as an argument. This has the advantange of easily working on multiple inputs:You are probably looking for val()
Output
If you are planning to use appending more then once, you might want to write a function:
After you can just call it:
Well when creating this example I somehow got a little confused. "ValueText" vs >Current NodeText< Isn't
.val()
supposed to run on the data of the value attribute? Anyway I and you me may clear up this sooner or later.However the point for now is:
When working with form data use .val().
When dealing with the mostly read only data in between the tag use .text() or .append() to append text.