【问题标题】:Wordpress tinymce insert textWordpress tinymce 插入文本
【发布时间】:2012-12-15 03:23:08
【问题描述】:

我在 wordpress 中遇到了 tinymce 的问题。我需要放入 tinymce 元素。在 tinymce 编辑器中,有两个选项卡“Visual”和“HTML”。当我在“HTML”中使用我的代码时,它的工作原理。但是当我想在“视觉”中使用它时它不起作用......

我是这样尝试的:

JavaScript

function insert_tag(text){
    var cont = document.getElementById('bbp_topic_content');
    cont.value += '<div>' + text + '</div>';
}

HTML

<a onclick="insert_tag('HELLO')" >Insert text</a>

有什么帮助吗?

【问题讨论】:

  • 你应该为tinyMCE创建一个插件来完成这种工作。查看this answer 了解一下。
  • 哪里没有简单的方法? :)

标签: wordpress tinymce


【解决方案1】:

你可以试试这个

function insert_tag(text){
    if(tinyMCE && tinyMCE.activeEditor)
    {
        tinyMCE.activeEditor.selection.setContent('<div>' + text + '</div>');
    }
    return false;
}

在你的a标签中也使用return

<a onclick="return insert_tag('HELLO')" >Insert text</a>

Reference.

【讨论】:

  • 非常感谢我会试试的
  • @user1139767,很高兴知道这一点。
猜你喜欢
  • 2013-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多