如何通过javascript将元素置于contenteditable模式

时间:2013-01-28 20:06:54

标签: javascript jquery html contenteditable

我有以下HTML元素

<p class="story" contenteditable="true">This is a story.</p>

现在我想通过javascript将元素置于编辑模式。我假设以下内容可行,但它没有

$('.story').click();

如何在没有用户点击元素的情况下手动将此元素置于编辑模式(通过javascript或任何其他方式)?

2 个答案:

答案 0 :(得分:3)

使用focus代替click

$(".story").focus();

答案 1 :(得分:-1)

$('.story').focus(function(){
    $(this).attr('contenteditable', 'true');
});