- onkeypress occurs when a keyboard key is pressed or held down
- onchange occurs when the content of a field changes
Ok, let's go further. If you want to validate the character number limitation of one textarea control, which one you should choose?
I told you that the onchange is better. Because if you use copy text from somewhere to this control, the onkeypress will not be effected; while, the onchange will be worked well.
And now, I think you can distinguish the two JavaScript events easily.
本文解析了JavaScript中onKeyPress与onChange事件的区别,强调了在验证文本区域字符限制时,onChange事件优于onKeyPress事件的原因,尤其是在复制粘贴操作下。
171

被折叠的 条评论
为什么被折叠?



