TinyMCE - 在底部插入内容 [英] TinyMCE - Insert Content at the bottom
本文介绍了TinyMCE - 在底部插入内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我们可以通过这种方式将代码插入到顶部。
I know we can insert the code to the top this way.
ed.selection.setCursorLocation(ed.getBody()。firstChild,0);
ed.selection.setCursorLocation(ed.getBody().firstChild, 0);
但是,我不知道如何在底部的内容中实现这一点。
But, I am not sure how to implement this for content at the bottom.
推荐答案
另一种方法:
function getTextNodes(node, nodeType, result){
var children = node.childNodes;
var nodeType = nodeType ? nodeType : 3;
var result = !result ? [] : result;
if (node.nodeType == nodeType) {
result.push(node);
}
for (var i=0; i<children.length; i++) {
result = this.getTextNodes(children[i], nodeType, result)
}
return result;
};
// get all Textnodes from lastchild, calc length
var textnodes = getTextNodes(ed.getBody().lastChild);
// set Cursor to last position
ed.selection.setCursorLocation(textnodes[textnodes.length-1], textnodes[textnodes.length-1].textContent.length );
这篇关于TinyMCE - 在底部插入内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文