How to get text of an input text box during onKeyPress?

前端 未结 12 1631
遥遥无期
遥遥无期 2020-11-28 05:12

I am trying to get the text in a text box as the user types in it (jsfiddle playground):

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 05:52

    Try to concatenate the event charCode to the value you get. Here is a sample of my code:

    
    

    js:

    function cnum(event, str) {
        var a = event.charCode;
        var ab = str.value + String.fromCharCode(a);
        document.getElementById('demo').innerHTML = ab;
    }
    

    The value in ab will get the latest value in the input field.

提交回复
热议问题