【问题标题】:how to get the image inserted from the tinymce editor?如何从 tinymce 编辑器中插入图像?
【发布时间】:2009-05-03 07:20:46
【问题描述】:

我正在尝试使用 tinymce 文本编辑器,但无法使用 jQuery 获取编辑器的内容,并且如果我使用简单的 post 方法获取值,我会得到文本,但没有得到图片?

我尝试使用 jQuery 的代码是:

$(document).ready(function()
{
    $("#save").click(function()
    {
        $.post("test_skin_dump.php",{
            data_info:$("#elm2").html;
        } ,function(data) {
            if(data)
            {
                $("#show_result").html(data);
            }               
        });
    });
}); 

<textarea id="elm2" name="elm2" rows="15" cols="80" style="width: 80%"> 
</textarea>

我做错了什么,请有人纠正我吗?

【问题讨论】:

    标签: php javascript jquery tinymce


    【解决方案1】:

    TinyMCE 有自己的 API,您可以利用它。事实上,它真的不算太糟糕。在您的情况下,您可以通过以下方式获取整个编辑器:

    tinyMCE.activeEditor().getBody();
    

    如果您确定用户点击了图像(即选中),那么您可以这样做以仅获取图像节点:

    tinyMCE.activeEditor().selection.createHTML();
    

    请注意,.selection 是一个属性,这就是它没有括号的原因。

    如果您不喜欢其中的任何代码,或者由于某种原因它不能完全回答您的问题,请随时查看以下链接:

    如果您还有其他需要,请告诉我。

    【讨论】:

      【解决方案2】:

      html 是一个函数。您缺少括号。你还有一个额外的分号。

      替换这个:

      data_info:$("#elm2").html;
      

      有了这个:

      data_info:$("#elm2").html()
      

      其余的看起来不错。

      【讨论】:

        【解决方案3】:

        使用以下命令将代码插入到您的编辑器中:

        tinyMCE.execCommand('mceInsertContent',false,'<img src="mypic.png" />');
        

        希望这会有所帮助:)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-25
          • 1970-01-01
          相关资源
          最近更新 更多