<输入>文字更改事件 [英] <input> text change events

查看:145
本文介绍了<输入>文字更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可以从< input type = text> (或contentEditable - 任何一行输入字段)元素中提取所有文本事件的库?



特别是,每当文字改变时,我都需要知道:




  • 键入(asdf,backspace)

  • 剪切/粘贴

  • 键组合动作(例如ctrl + bksp或选项+ bksp删除上一个单词) li>
  • dragged&删除文本

  • 编辑菜单操作



最好是改变了什么文本被插入,删除或替换)。



需要在Chrome,Safari,Firefox 3+,IE9 +上工作。

解决方案

所有这些浏览器都支持HTML5 oninput 事件,非常像 onchange 事件,但一旦元素的输入更改,就会触发。它也是泡沫,所以你可以在文档树上进一步捕获它。

  element.oninput = function(){

}

工作演示: http://jsfiddle.net/Zfthe/



http://whattheheadsaid.com/2010/09/effectively-detecting-user-input -in-javascript


Is there a library that can extract all text events from an <input type=text> (or contentEditable -- any one-line input field) element?

In particular, I need to know whenever the text is changed by:

  • typing (asdf, backspace)
  • cut/paste
  • key combo actions (e.g. ctrl+bksp or option+bksp deletes the previous word)
  • dragged & dropped text
  • edit menu actions

And preferably what it was that changed (whether and what text was inserted, deleted, or replaced).

Needs to work on Chrome, Safari, Firefox 3+, IE9+.

解决方案

The HTML5 oninput event is supported by all those browsers and works very much like the onchange event, but fires as soon as the element's input changes. It also bubbles, so you can capture it further up the document tree.

element.oninput = function () {

}

Working demo: http://jsfiddle.net/Zfthe/

http://whattheheadsaid.com/2010/09/effectively-detecting-user-input-in-javascript

这篇关于&LT;输入&GT;文字更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆