Is it possible to use JavaScript to listen for text typed in a specific text-field, and then grab that text and save it to a string. Well, the latter (e.g., saving to string) will of course be possible if the former can be done.
I found a Java Applet that does this (.0/ui/textlistener.html), but I was wondering if the same could be done with JS.
I'm just looking for some resources/docs.
If anyone can help, I'd much appreciate it!
Is it possible to use JavaScript to listen for text typed in a specific text-field, and then grab that text and save it to a string. Well, the latter (e.g., saving to string) will of course be possible if the former can be done.
I found a Java Applet that does this (http://journals.ecs.soton.ac.uk/java/tutorial/post1.0/ui/textlistener.html), but I was wondering if the same could be done with JS.
I'm just looking for some resources/docs.
If anyone can help, I'd much appreciate it!
Share Improve this question edited Nov 7, 2022 at 22:18 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Sep 8, 2011 at 12:37 ArtSabintsevArtSabintsev 5,20011 gold badges43 silver badges72 bronze badges 1- 1 problem here : you won't be able to catch if the user keep touch down. So if he enters "aaaaaaaaaaaaa" you'll catch it only when he'll release the "a" key. – remi bourgarel Commented Sep 8, 2011 at 12:47
3 Answers
Reset to default 4simple with jQuery
$('input[name=your-input]').change( function () {
alert(this.value); //or alert( $(this).val() );
});
I'd remend trying JQuery which will allow you to bind to the keydown event of any element you select: http://api.jquery./keydown/
However, you might want to only update the string after the user has finished typing, so you might want to consider updating it whenever the textfield loses focus - which you can do by binding to the blur
event in the same way.
EDIT: Yes - realise I was being a bit stupid here. change
is the event you should bind to for this.
In vanilla javascript you add an event listener:
document.getElementById('your-input').addEventListener('input', ()=>{
console.log(this.value);
})
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745125047a4612638.html
评论列表(0条)