Listening to events of a contenteditable HTML element

后端 未结 4 812
陌清茗
陌清茗 2020-12-05 15:07

I\'m trying to figure out if there is any way to listen to events like focus or change of an HTML element with contenteditable attribu

4条回答
  •  天命终不由人
    2020-12-05 15:59

    Not really. There is no change event for contenteditable elements, and there's no HTML5 input event either, although I think that will eventually appear. It's a pain.


    UPDATE 23 June 2012

    Recent WebKit supports the HTML5 input event on contenteditable elements, as does Firefox 14.


    focus, however, does work, as does DOMCharacterDataModified in most browsers (though notably not IE < 9). See http://jsfiddle.net/UuYQH/112/

    By the way, contenteditable is not a Boolean attribute: it requires a value, which should be one of "true", "false", "inherit" and the empty string (which is equivalent to "true").

提交回复
热议问题