已编辑 html 个元素的值

Value of an html element edited

为什么这段代码在 Firefox 中不起作用? 目标是在元素失去焦点时获取编辑后的值

out = document.getElementById('out');
edit = function(e) {
  var element = e;
  element.contentEditable = true;
  element.onblur = function(blur) {
    console.log(element.innerText);
    out.innerText = element.innerText;
  };
};
span {
  background-color: cyan;
}
#out {
  background-color: yellow;
  padding: 0.5em;
}
<span ondblclick="edit(this)" data-foo="foo" data-bar="bar">
    double-click and edit-me</span>

<p></p>
<span id="out"></span>

Firefox 不支持 .innerText。您应该改用 W3 标准 .textContent

这将适用于所有现代浏览器,如果需要可以修补到 IE8 中。