简体   繁体   English

EditorJS 在点击时自动对焦

[英]EditorJS autofocus on click

I`m using EditorJS ( https://editorjs.io/ )我正在使用 EditorJS ( https://editorjs.io/ )

I have a hidden div with editor holder in it and a separate button (Add new for ex) I need this div to appear when user click on the button我有一个带有编辑器支架的隐藏 div 和一个单独的按钮(为前添加新的)我需要这个 div 在用户点击按钮时出现

everything is working fine一切正常

but I can't set up autofocus so that the user doesn't click on the holder to start working with editor但我无法设置自动对焦,因此用户不会点击支架开始使用编辑器

i tried doing我试着做

setTimeout(function(){ $('#editor').click()}, 100);

but it doesn't work但它不起作用

If I understood your growth correctly https://editorjs.io/configuration#autofocus如果我正确理解你的成长https://editorjs.io/configuration#autofocus

There a config key:有一个配置键:

const editor = new EditorJS(
  autofocus: true
})

Ok, here is the solution:好的,这是解决方案:

<div id="editorjs"></div>
<button id="focus">focus</button>

And initialization :和初始化:

const editor = new EditorJS({ 
  
  
  holder: 'editorjs', 
  
  onReady: function () {
    const btn = document.querySelector("#focus");
    btn.addEventListener("click", () => editor.focus())
  }

})

And link for example : https://codepen.io/Ashley100/pen/mdEqoRY?editors=1010和链接例如: https : //codepen.io/Ashley100/pen/mdEqoRY?editors=1010

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM