问题描述
我正在使用EditorJS(https://editorjs.io/)
我有一个隐藏的div,其中包含编辑器夹和一个单独的按钮(为ex添加新功能) 当用户单击按钮时,我需要显示该div
一切正常
但是我无法设置自动对焦,以便用户不会单击固定器来开始使用编辑器
我尝试做
setTimeout(function(){ $('#editor').click()},100);
但这不起作用
解决方法
如果我正确理解了您的成长 https://editorjs.io/configuration#autofocus
有一个配置键:
const editor = new EditorJS(
autofocus: true
})
,
好,这是解决方法:
<div id="editorjs"></div>
<button id="focus">focus</button>
和初始化:
const editor = new EditorJS({
holder: 'editorjs',onReady: function () {
const btn = document.querySelector("#focus");
btn.addEventListener("click",() => editor.focus())
}
})