我在内容发生变化时尝试从nicEdit实例复制内容:
var myInstance = new nicEditor({ iconsPath : 'https://cdn.jsdelivr.net/nicedit/0.9r24/nicEditorIcons.gif'}).panelInstance('drag_words_paragraph');
myInstance.addEvent('blur', function() {
var nicInstance = nicEditors.findEditor('drag_words_paragraph');
var drag_words_paragraph11 = nicInstance.getContent();
$("#list_id").html(drag_words_paragraph11);
});
相反,当我点击页面上的任何位置时,我会收到提醒。我该如何解决这个问题?
答案 0 :(得分:0)
如上一篇文章所述,请尝试以下代码段。如果您收到任何错误,请告诉我。此处仅在文本更改时触发警报。
body {
min-height: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/nicedit/0.9r24/nicEdit.js"></script>
<textarea class="form-control" style="width: 300px; height: 100px;" name="drag_words_paragraph" id="drag_words_paragraph">
Enter your text here...
</textarea>
<br/>
<p id="list_id"></p>
<script>
var drag_words_paragraph;
$(function() {
window.drag_words_paragraph = $('#drag_words_paragraph').text();
var myInstance = new nicEditor({
iconsPath: 'https://cdn.jsdelivr.net/nicedit/0.9r24/nicEditorIcons.gif'
}).panelInstance('drag_words_paragraph');
myInstance.addEvent('blur', function() {
debugger;
var text = this.instanceById('drag_words_paragraph').getContent();
if (window.drag_words_paragraph == text) {
$("#list_id").html(text);
return false;
} else {
alert('text changed');
window.drag_words_paragraph = text;
$("#list_id").html(text);
}
});
});
</script>