2
현재 summernote 0.8.2를 사용하고 있으며 텍스트가 사전로드 된 메모를 사용하고 있습니다. 텍스트가로드되면 초점을 맞추고 싶지만 줄의 끝에 초점을 맞추고 싶습니다. 나는 API을 기반으로 초점을 맞추려고했습니다. 그러나 초점을 맞추었지만 줄의 끝에서 시작하지 않습니다. 다음은 this 질문을 기반으로 한 작업의 예입니다. 도와주세요. 는Summernote 텍스트 끝 부분에 초점 맞추는 방법
$("#myNote").summernote({
toolbar: [
['para', ['ul']]
],
focus: true
});
$('.note-editor [data-event="insertUnorderedList"]').tooltip('disable');
$('.note-btn.btn.btn-default.btn-sm').attr('data-original-title','');
var html = "<ul><li>item 1</li><li>item 2<br></li></ul>";
$("#myNote").summernote('code',html);
$("#myNote").focus();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script>
<script>
$(document).ready(function() {
$.fn.extend({
placeCursorAtEnd: function() {
// Places the cursor at the end of a contenteditable container (should also work for textarea/input)
if (this.length === 0) {
throw new Error("Cannot manipulate an element if there is no element!");
}
var el = this[0];
var range = document.createRange();
var sel = window.getSelection();
var childLength = el.childNodes.length;
if (childLength > 0) {
var lastNode = el.childNodes[childLength - 1];
var lastNodeChildren = lastNode.childNodes.length;
range.setStart(lastNode, lastNodeChildren);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
return this;
}
});
});
</script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet"/>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet"/>
<div id="myNote"></div>