Backspace deletes whole span element

送分小仙女□ 提交于 2021-02-07 19:25:21

问题


Is it possible to prevent span deletion with backspace?

<div class="form-control" contenteditable="true">
  <span class="correct-answer">
    <span contenteditable="false">The correct answer is (A) 1 to 2. </span>
    <span class="sentence" num="11">dgsdgsg. sgsdgs sgsgs.</span>
  </span>
</div>

Example: http://jsfiddle.net/pvj64px9/1/

The correct answer is (B) 2 to 3. and `Choice A (1 to 2) is incorrect. ` must not be deleted.

回答1:


update your parent container to have contenteditable="false"

<div id="window-kitkat" class="form-control" contenteditable="false">

and set the individual elements you want as editable to true, e.g.,

<span class="sentence" num="10" contenteditable="true">jfbgfdgdf sgdsgsd.</span>


来源:https://stackoverflow.com/questions/32640360/backspace-deletes-whole-span-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!