2016-11-14 53 views
2

我需要选择刚刚插入Froala textarea上的一段文本。以下是我试过的:在Froala上选择插入的文本

// wrapper is used to get the outerHTML 
var wrapper = $('<span/>'); 
var content = $('<p/>', { 'class': 'schedule' }); 
content.html(value); 
wrapper.append(content); 
editor.froalaEditor('html.insert', wrapper.html()); 
editor.froalaEditor('selection.setAtEnd', $('.schedule')[0]); 

还尝试添加一个selection.setAtStart调用;使用markers模块;加入selection.restore;集中textarea和其他一些尝试,但没有任何工作。

这应该如何实现?

谢谢。

回答

1

所以通过Froala的GitHub的问题进行搜索后,我发现这一点:

$('#editor').html('<p></p>'); 
$('#editor').froalaEditor(); 
var $p = $('#editor').data('froala.editor').$el.find('p:first'); 
$p.html('foo' + $.FroalaEditor.START_MARKER + 'bar' + $.FroalaEditor.END_MARKER); 
$('#editor').froalaEditor('selection.restore'); 

(来源:https://github.com/froala/wysiwyg-editor/issues/803

它看起来像有选择插入的内容以特殊的方式和文档并没有提到它。