繁体   English   中英

如何使用javascript选择CKEditor工具栏项目?

[英]How to select an CKEditor toolbar item using javascript?

我正在我的iOS应用程序上实现CKEditor,问题是我需要检测工具栏项目上的触摸。我有一个UIWebView,它显示CKEditor'demo.html'和一个用于测试过程的按钮,单击该按钮时它在“ demo.html”文件上触发一个javascript函数,代码如下:

来自“ demo.html”的Javascript:

<script type="text/javascript">

    function mateus(){

        // SIMULATE TOUCH ON TOOLBAR ITEM

    }

    CKEDITOR.replace( 'editor1',
            {
                extraPlugins : 'uicolor',
                removePlugins: 'elementspath',
                toolbar :
                [
                    [ 'Bold', 'Italic', 'Underline','NumberedList','BulletedList']
                ]
});
</script>

UIButton动作:

-(IBAction)buttonTester:(id)sender{

    [webView stringByEvaluatingJavaScriptFromString:@"mateus()"];

}

这部分工作正常,问题是,就像我之前说的那样,我需要模拟工具栏项目上的触摸,而且我不知道该怎么做!

简化:

如何使用javascript选择CKEditor工具栏项目?

编辑------------------------------------------------- ---------------------

我进行了更多搜索,并在CKEditor文档中找到了以下片段:

editorInstance.execCommand( 'bold' );

但是我无法使用它,这是我的新尝试:

function mateus(){

            CKEDITOR.instances.editor1.execCommand('bold');

}

终于我明白了,就像看似简单:

要选择一个具有JavaScript函数功能的工具栏项目,请使用以下代码段:

function mateus(){

    //Desired item from toolbar, like:('Italic','Underline','Image');
    CKEDITOR.instances.editor1.execCommand('bold');

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM