I need to simulate the user input of a character, for example ()
< Code> & lt; Textarea rows = 3 cols = '30 'id =' txt '& gt; & Lt; / Textarea & gt; & Lt; Script & gt; Var $ txt = jQuery ('# txt') var e = jQuery.Event ("keypress"); E.which = 49; $ Txt.focus () Trigger (E) & lt; / Script & gt;This sets the focus on texterrari correctly, but the character '1' (ASCI code 49) does not appear in the text box. What am i doing wrong
UPDATE: Based on the answers, I see that I have not provided enough information, so here it goes: The issue is not just changing the value of the text field, but in reality, Use it to simulate to enter that value. I'm trying to hook into some SharePoint control, and when the user presses a certain key in some teddytra, then it does a lot of stuff. I will not be good by adding some value through the value of Val () Key events need to be triggered.
So, the question is still there - how do I simulate user input I tried in the example above?
Use instead:
var $ Txt = jQuery ( '# Txt'); $ Txt.focus () Val ('1').
And in fact, you do not need the
Focus () method for this purpose.
> "); Txt.value =" 1 ";
No comments:
Post a Comment