【问题标题】:tinyMCE plugin accessing elementtinyMCE 插件访问元素
【发布时间】:2013-12-22 20:23:07
【问题描述】:

我正在尝试编写一个 tinymce 插件,因此我查看了 http://www.tinymce.com/ 上的教程“创建插件”。插入和替换内容没问题,一切正常。

现在我想在更改列表框的值后自动更改文本框的值。例如,更改列表框元素后,应将活动元素的值写入上面的文本框。我怎样才能访问这个元素?

tinymce.PluginManager.add('myexample', function(editor, url)  {
// Add a button that opens a window
editor.addButton('myexample', 
{
    text: 'Example',
    onclick: function() 
    {
        // Open window
        editor.windowManager.open({
            title: 'Example Plugin',
            body: [
                // Text
                {type: 'textbox', name: 'title', label: 'Text', value: 'temp'},
                // Listbox
                {type: 'listbox', name: 'test', label: 'Ziel', 
                    'values': 
                    [
                        {text: 'Eins', value: '1'},
                        {text: 'Zwei', value: '2'}
                    ],                  
                    onselect: function(v) 
                    {
                        console.log(this.value());

                        // CHANGE THE VALUE OF THE TEXTBOX ...
                        // ????
                    }
                }
            ],
            onsubmit: function(e) 
            {
                console.log(e.data.title, e.data.test);
            }
        });
    }
});

});

【问题讨论】:

    标签: javascript plugins tinymce


    【解决方案1】:

    我知道这是一个老问题,但我遇到了同样的问题,我在另一个论坛上找到了 this answer,这挽救了我的一天。

    执行此操作的标准 tinymce 方法是将弹出窗口保存在变量中:

    var win = editor.windowManager.open({ //etc
    

    然后用于访问元素:

    win.find('#text'); // where text is the name specified
    

    我希望这可以在将来对其他人有所帮助。

    【讨论】:

      【解决方案2】:

      现在我找到了解决方案。最好的方法是不使用内部表单设计器。您可以将 IFrame 与外部 html 页面一起使用,然后您可以使用 document.getElementById(...)

      Here你可以找个例子

      【讨论】:

      • 一点也不。首先,tinymce windowmanager 会动态生成 id,因此 ;) 其次,您可以在一个页面上拥有数千个元素,并且 id 不能是唯一的。
      猜你喜欢
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多