jquery keyup 忽略不变的字符
我试图在使用 keyup 更改 contenteditable div 时触发一个事件。不幸的是,它也捕获了诸如用箭头键移动插入符号之类的东西。我只想让它发现实际的变化。
我读了这个问题,看起来很相似,但是那里的解决方案不适用于换行之类的事情。有想法吗?
I'm trying to get an event to fire whenever a contenteditable div is changed using keyup. Unfortunately it's also catching things like moving the caret with the arrow keys. I only want it to spot actual changes though.
I read this question, which seems similar, but the solution on there doesn't work for things like linebreaks. Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是在处理程序外部缓存长度,然后将文本区域的当前长度与缓存的长度进行比较。如果它们不同,那么您可以假设按下的键将内容添加到文本区域。希望这有帮助。
One way would be to cache the length outside the handler then compare the current length of the textarea against your cached length. If they differ then you can assume the key that was pressed added content to the textarea. Hope this helps.