单击图标打开tinymce编辑器

时间:2016-03-29 14:22:55

标签: javascript tinymce

加载页面后,我希望关闭tinyMCE编辑器。单击一个元素(而不是文本,因此我认为我不应该使用内联模式),我希望打开它。我发现了几种方法。是否有“正确”的方式,如果有,那是什么?

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Testing</title>  
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js" type="text/javascript"></script>
        <script src="//tinymce.cachefly.net/4.0/tinymce.min.js" type="text/javascript"></script>
        <style type="text/css">
            #content {height:200px;width:400px;border: 1px solid;}
        </style>
        <script type="text/javascript">
            $(function(){
                // Don't want this as I want to edit upon clicking "edit" and not inline
                tinymce.init({
                    selector: '#content',
                    width : 400,
                    height: 200,
                    inline: true,
                });

                // Don't like this as I think it is ineffient, and the screen flickers
                $('#edit').click(function(){
                    tinymce.init({
                        selector: '#content',
                        width : 400,
                        height: 200
                    });
                });

                // Is this how I should do it?
                tinymce.init({
                    selector: '#content',
                    width : 400,
                    height: 200,
                    setup : function(ed) {
                        ed.on('init', function(e) {
                            e.target.hide();
                        });
                    }
                });
                $('#edit').click(function(){
                    //BOth seem to work.  What is the right way?
                    //tinymce.editors['content'].show();
                    tinymce.get('content').show();
                });

            });
        </script>
    </head>

    <body>
        <div id="content">Initial content goes here</div>
        <button id="edit">Edit</button>
    </body> 
</html> 

0 个答案:

没有答案