在Froala init()中设置焦点,请按以下步骤操作:
$('div#froala-editor')
.on('froalaEditor.initialized', function (e, editor) {
editor.events.focus(true);
}).froalaEditor({
......editor init settings...
})
这里使用jQuery事件机制来捕获froalaEditor.initialized事件,然后使用传入的editor对象调用focus方法。
如果需要在Froala初始化之后任何时间进行程序化地聚焦,可以使用以下方法:
$('selector').froalaEditor('events.focus', true).
例如,在这里我使用延迟来模拟Froala init()和focus调用之间经过的时间:
setTimeout(function(){
$('#edit').froalaEditor('events.focus', true);
console.clear()
console.log('fired focus trigger!')
}, 2000)
虽然这很有用,但并不是当前Froala API文档的要点,该文档没有提供这方面的见解,而似乎暗示语法应该是:
$('#selector').froalaEditor('events.trigger', 'focus');
我尝试了一下,但无法使其工作。也许Froala应该考虑澄清文档。
感谢Froala支持团队的Stefan及时响应我的求助。