Javascript TinyMCE-在底部插入内容

Javascript TinyMCE-在底部插入内容,javascript,tinymce,Javascript,Tinymce,我知道我们可以通过这种方式将代码插入顶部 ed.selection.setCursorLocation(ed.getBody().firstChild,0) 但是,我不知道如何为底层内容实现这一点 您可以使用以下to方法向文档体添加新的HTML元素 例如,下面添加了一个CSS类为“text_it”的空段落 另一种方法: function getTextNodes(node, nodeType, result){ var children = node.childNodes; v

我知道我们可以通过这种方式将代码插入顶部

ed.selection.setCursorLocation(ed.getBody().firstChild,0)


但是,我不知道如何为底层内容实现这一点

您可以使用以下to方法向文档体添加新的HTML元素

例如,下面添加了一个CSS类为“text_it”的空段落

另一种方法:

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 );
函数getTextNodes(节点、节点类型、结果){ var children=node.childNodes; var nodeType=nodeType?nodeType:3; 变量结果=!结果?[]:结果; if(node.nodeType==nodeType){ 结果:推送(节点); }
对于(var i=0;我会说:更好的方法
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 );