我有以下HTML元素
<p class="story" contenteditable="true">This is a story.</p>
现在我想通过javascript将元素置于编辑模式。我假设以下内容可行,但它没有
$('.story').click();
如何在没有用户点击元素的情况下手动将此元素置于编辑模式(通过javascript或任何其他方式)?
答案 0 :(得分:3)
使用focus
代替click
:
$(".story").focus();
答案 1 :(得分:-1)
$('.story').focus(function(){
$(this).attr('contenteditable', 'true');
});