【问题标题】:Get html of a table in TinyMCE (using the table plugin)在 TinyMCE 中获取表格的 html(使用表格插件)
【发布时间】:2011-07-08 07:26:48
【问题描述】:

我有一个加载了表格插件的 TinyMCE 编辑器(我使用的是 TinyMCE Advanced Wordpress 插件)。我必须获取选定表格的 HTML 代码(您当前正在编辑的表格 - 您已打开调整大小控件)。对于普通文本,我可以使用tinyMCE.activeEditor.selection.getContent(),但这在处理表格时不起作用。这样做的正确方法是什么?

谢谢。

【问题讨论】:

    标签: javascript tinymce


    【解决方案1】:

    您可以使用tinyMCE.activeEditor.selection.getNode();。如果这是一个表格元素,你得到了你的表格,并且能够使用

    获取 html
    var node = tinyMCE.activeEditor.selection.getNode();
    var html = node.innerHTML;
    // now you will only need to take care of the surrounding table element
    // something like "<table>"+ html +"</table>"; maybe having a look at node.attributes
    

    【讨论】:

    • 谢谢。最终的解决方案有点长:$(tinyMCE.activeEditor.selection.getNode()).parents('table.mceItemTable:first')
    • 对,这是使用 jQuery 获取整个父级的最简单方法
    • 我在尝试使用 jQuery 函数时收到无效的错误字符消息。如何使 jQuery 在我的 editor_plugin.js 中可用? @Thariama - 用你的解决方案我得到了tbody 标签而不是table 一个,有什么想法如何得到一张桌子?
    • $(node).parents('table').first()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 2019-12-08
    • 1970-01-01
    • 2020-01-28
    • 2016-04-24
    相关资源
    最近更新 更多