【发布时间】:2018-05-07 18:17:28
【问题描述】:
我有一个内容可编辑的 div,并附有一个 keyup 事件。当用户键入时,在该 div 中创建了许多 p 标签。
$(".pad").keyup(function(e) {
doSomething();
});
这就是keyup 事件。
如何确定用户在 contenteditable div 中编辑/创建了哪个元素?
我尝试了以下方法,但似乎不起作用:
$(".pad p").keyup(function(e) {
doSomething();
});
我们的目标是拥有这样的东西:
$(".pad").keyup(function(e) {
theEditedElement = ...;
$(theEditedElement).css("color","red");
$(theEditedElement).(...);
});
我们开始:
<div class="pad" contenteditable="true">
<p>Some text</p>
</div>
然后用户将其编辑为:
<div class="pad" contenteditable="true">
<p>Some text</p>
<p>Some more text</p>
<p>Even <b>more</b> text</p>
</div>
如果用户决定编辑<p>Some more text</p>,则应检索特定的<p> 元素。
【问题讨论】:
标签: javascript jquery keypress contenteditable keyup