get text box value when i type the value by every press

ε祈祈猫儿з 提交于 2019-12-25 03:05:28

问题


i want to know get text box value when i type the value by every press.

i have to get the value.

if i type numbers i have to get. so i have checking with that value.

thanks in advance


回答1:


Probably you will have to serve events on input field: onkeypress, onkeyup, onkeydown, onpaste, onchange.




回答2:


var my_input = document.getElementById('my_input');
my_input.onkeyup = function() {
  alert(my_input.value);
}
<input type='text' id='my_input' />



回答3:


You can get the value of an input element from its value property, e.g.

element.value

To execute some function on every key press, you should bind an event handler for the keyup event to this element.

You should make yourself familiar with event handling in JavaScript and the variations in the different browsers. The site I linked to (quirksmode.org) is a very good resource for that.




回答4:


One thing to note is that in certain browsers the method by which you get the value of a textarea differs. I'm thinking in IE6, at least, it actually registers the value of a textarea as it's innerHTML (or the other way around).

Worth doing a check in you eventListener for if the value is set, or not, and checking the innerHTML if it's not, just in case!



来源:https://stackoverflow.com/questions/3750968/get-text-box-value-when-i-type-the-value-by-every-press

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!