How to get the new value of an HTML input after a keypress has modified it?

后端 未结 6 1773
北恋
北恋 2021-02-05 03:24

I have an HTML input box


I\'ve attached a handler for the \'keyup\' event, but if

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 03:56

    There are two kinds of input value: field's property and field's html attribute.

    If you use keyup event and field.value you shuld get current value of the field. It's not the case when you use field.getAttribute('value') which would return what's in the html attribute (value=""). The property represents what's been typed into the field and changes as you type, while attribute doesn't change automatically (you can change it using field.setAttribute method).

提交回复
热议问题