[英]How do I put an element into contenteditable mode via javascript
I have the following HTML element 我有以下HTML元素
<p class="story" contenteditable="true">This is a story.</p>
Now I want to put the element into edit mode via javascript. 现在我想通过javascript将元素置于编辑模式。 I assumed something like the following would work, but it doesn't 我假设以下内容可行,但事实并非如此
$('.story').click();
How can I manually put this element in edit mode (via javascript or any other way) without the user clicking on the element? 如何在没有用户点击元素的情况下手动将此元素置于编辑模式(通过javascript或任何其他方式)?
使用focus
而不是click
:
$(".story").focus();
$('.story').focus(function(){
$(this).attr('contenteditable', 'true');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.