How to inactivate contentEditable

落爺英雄遲暮 提交于 2020-01-24 09:11:11

问题


I have a webpage with an img. Each time the user clicks on the img, it will generate a span tag with the contentEditable attribute set to true.

My problem is that if the user clicks on the img to add a span, clicks on the span (thus activating the editable zone), then clicks back on the img, it will add another editable span (desired effect) but it will also leave the first span in edit mode.

How can I change back the editable span into a normal span?


回答1:


You can remove the contenteditable attribute and the focus with jQuery like this:

$('span#id').removeAttr('contenteditable').blur();

If you want to style all spans that can be edited you can do it like this in CSS:

span[contenteditable] { } /* editable */


来源:https://stackoverflow.com/questions/8603807/how-to-inactivate-contenteditable

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