I'm wondering how I can capture the recently inserted value of a contenteditable. I have

<section id="content" contenteditable="true">
</section>

<script>
  function parse(e) {
    console.log(e);
  }

  var el = document.getElementById("content");
  el.addEventListener("input", parse, false);
</script>

It seems as though the event doesn't carry any information regarding what content was just inserted. Is there another "out-of-the-box" method that could capture this? I'm not very familiar with mutation events, but is that perhaps my best shot?

有帮助吗?

解决方案

Well, this may be a poor-mans solution, but hooking it up with a keypress event listener gave me the keycode for the recently pressed key

function doKeyPress(e) {
  console.log(e.keycode)
}

var el = document.getElementById("content");
el.addEventListener("keypress", doKeyPress, false);

Just a matter of mapping keycodes to values to get there.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top