這是很簡單的JavaScript調用:獲取段落的ID內CKEDITOR 4
CKEDITOR.instances.yourEditorInstance.getData()
返回:
<p id="rand_dom_123">Python A B C</p>
<p id="rand_dom_852">PHP A B C D E F</p>
但是:
CKEDITOR.instances.yourEditorInstance.editable().getText()
返回:
Python A B C
PHP A B C D E F
這是我的代碼:
$('.jquery_ckeditor').ckeditor(config);
CKEDITOR.instances['editor'].on('blur', function() {
var html_content = CKEDITOR.instances['editor'].getSelection().getSelectedText() ;
alert(html_content);
});
我怎樣才能得到所選段落的ID
?例如,我可以知道它的段落編號,如果我選擇A B C
問題是我想獲取選定段落的ID。 – kn3l
@BandOfBrothers使用範圍 – giammin
var html_content = CKEDITOR.instances ['editor']。getSelection()。getRanges()。createIterator(); \t \t \t id = html_content.getAttribute('id'); \t \t \t alert(id);不起作用。 – kn3l