Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过Jquery禁用TinyMCE文本编辑器_Javascript_Jquery_.net_Tinymce - Fatal编程技术网

Javascript 通过Jquery禁用TinyMCE文本编辑器

Javascript 通过Jquery禁用TinyMCE文本编辑器,javascript,jquery,.net,tinymce,Javascript,Jquery,.net,Tinymce,我有多个微型MCE编辑器,我正试图禁用编辑功能。我尝试了以下多种变体: if(@Model.hasRegular.ToString().ToLower()) { tinymce.get('#rte').getBody().setAttribute('contenteditable', false); } if(@Model.hasSmall.ToString().ToLower()) { t

我有多个微型MCE编辑器,我正试图禁用编辑功能。我尝试了以下多种变体:

if(@Model.hasRegular.ToString().ToLower()) 
        {
          tinymce.get('#rte').getBody().setAttribute('contenteditable', false);
        }
        if(@Model.hasSmall.ToString().ToLower())
        {
          tinymce.get('#rteSmall').getBody().setAttribute('contenteditable', false);
        }
        if(@Model.isOneSize.ToString().ToLower())
        {
          tinymce.get('#rteOneSize').getBody().setAttribute('contenteditable', false);
        }
“我的编辑器”的定义类似于:

tinymce.init({
          selector: '#rte',
          toolbar: 'bold italic underline',
          height: '200px',
          width: '420px',
          elementpath: false,
          menubar: false,
          content_style: "div {border: 50px solid red;}",

          setup: function (ed) {
            ed.on('init', function () {
              this.getDoc().body.style.fontSize = '16px';
              this.getDoc().body.style.fontFamily = 'Helvetica';
              //disables editing for non admins
              if ($('#nonAdmin').length) {
                this.setMode('readonly');
              }

            });
          }

        });
当前,在我尝试的过程中,我遇到了一个控制台错误:
无法读取null的属性“getBody”
您对tinymce.get()的调用不正确

get()的API声明:

按id:get(id:String):tinymce.editor返回编辑器实例

参数: id(字符串)-要返回的编辑器实例id或索引

这不是jQuery API调用,因此您的调用:

tinymce.get('#rteSmall')
…应该是

tinymce.get('rteSmall')
您对tinymce.get()的调用不正确

get()的API声明:

按id:get(id:String):tinymce.editor返回编辑器实例

参数: id(字符串)-要返回的编辑器实例id或索引

这不是jQuery API调用,因此您的调用:

tinymce.get('#rteSmall')
…应该是

tinymce.get('rteSmall')

您的禁用代码中有一个输入错误:

tinymce.get('#rte').getBody().setAttribute('contenteditable', false);
该行必须是:

tinyMCE.get('rte').getBody().setAttribute('contenteditable', false);
因此,请删除#符号

因为您已经使用了setMode,所以可以执行以下操作:

tinyMCE.get('rte').setMode('readonly');

片段(小提琴:):

$(函数(){
$('#nonAdmin')。关于('change',函数(e){
tinyMCE.get('rte').getBody().setAttribute('contenteditable',!this.checked);
});
tinymce.init({
选择器:“#rte”,
工具栏:“粗体斜体下划线”,
高度:“200px”,
宽度:“420px”,
元素路径:false,
梅努巴:错,
content_样式:“div{border:50px实心红色;}”,
设置:功能(ed){
ed.on('init',函数(){
this.getDoc().body.style.fontSize='16px';
this.getDoc().body.style.fontFamily='Helvetica';
//禁用非管理员的编辑
if($('#nonAdmin').prop('checked')){
此.setMode('readonly');
}
});
}
});
});

TinyMCE快速入门指南
禁用:
你好,世界!

您的禁用代码中有一个输入错误:

tinymce.get('#rte').getBody().setAttribute('contenteditable', false);
该行必须是:

tinyMCE.get('rte').getBody().setAttribute('contenteditable', false);
因此,请删除#符号

因为您已经使用了setMode,所以可以执行以下操作:

tinyMCE.get('rte').setMode('readonly');

片段(小提琴:):

$(函数(){
$('#nonAdmin')。关于('change',函数(e){
tinyMCE.get('rte').getBody().setAttribute('contenteditable',!this.checked);
});
tinymce.init({
选择器:“#rte”,
工具栏:“粗体斜体下划线”,
高度:“200px”,
宽度:“420px”,
元素路径:false,
梅努巴:错,
content_样式:“div{border:50px实心红色;}”,
设置:功能(ed){
ed.on('init',函数(){
this.getDoc().body.style.fontSize='16px';
this.getDoc().body.style.fontFamily='Helvetica';
//禁用非管理员的编辑
if($('#nonAdmin').prop('checked')){
此.setMode('readonly');
}
});
}
});
});

TinyMCE快速入门指南
禁用:
你好,世界!
TinyMCE(最新版本)文本编辑器在文档准备就绪时禁用某些样式

    $(function () {
        tinymce.init({
                            selector: '#textEditor',
                            plugins: "advlist lists table paste textcolor colorpicker tabfocus link preview",
                            toolbar: "table fontsizeselect bold italic underline forecolor backcolor bullist numlist link preview code", imagetools_toolbar: "rotateleft rotateright | flipv fliph | editimage",
                            menubar: false,
                            toolbar_items_size: 'large',
                            min_height: 500,
                            max_height: 800,
                            convert_newlines_to_brs: false,
                            statusbar: false,
                            relative_urls: false,
                            remove_script_host: false,
                            language: 'en',
        
                        });
                        
                //controls disable inside sections
                tinyMCE.get('textEditor').setMode('readonly');  // disable
                setTimeout(function () {
                    $(".tox .tox-edit-area__iframe, .tox- 
                    toolbar__primary").css("background", "#eee");
                    $(".tox-tinymce").css("border", "1px solid #eee");

                }, 1000);
        });



               //if you want to enable it again, using your own button
                  $(".editFormControls").on('click', function () {
                  $(".sections form").find(".updateControl").show();
               });
TinyMCE(最新版本)文本编辑器在文档准备就绪时禁用某些样式

    $(function () {
        tinymce.init({
                            selector: '#textEditor',
                            plugins: "advlist lists table paste textcolor colorpicker tabfocus link preview",
                            toolbar: "table fontsizeselect bold italic underline forecolor backcolor bullist numlist link preview code", imagetools_toolbar: "rotateleft rotateright | flipv fliph | editimage",
                            menubar: false,
                            toolbar_items_size: 'large',
                            min_height: 500,
                            max_height: 800,
                            convert_newlines_to_brs: false,
                            statusbar: false,
                            relative_urls: false,
                            remove_script_host: false,
                            language: 'en',
        
                        });
                        
                //controls disable inside sections
                tinyMCE.get('textEditor').setMode('readonly');  // disable
                setTimeout(function () {
                    $(".tox .tox-edit-area__iframe, .tox- 
                    toolbar__primary").css("background", "#eee");
                    $(".tox-tinymce").css("border", "1px solid #eee");

                }, 1000);
        });



               //if you want to enable it again, using your own button
                  $(".editFormControls").on('click', function () {
                  $(".sections form").find(".updateControl").show();
               });

检查控制台。如果有任何错误。如果有多个..,请尝试此操作。tinyMCE.get('rte').getBody().setAttribute('contenteditable',false);同样,从4.3.x版开始,您可以将下面的代码用于只读模式。。它类似于tinymce.activeEditor.setMode('readonly');检查控制台。如果有任何错误。如果有多个..,请尝试此操作。tinyMCE.get('rte').getBody().setAttribute('contenteditable',false);同样,从4.3.x版开始,您可以将下面的代码用于只读模式。。它类似于tinymce.activeEditor.setMode('readonly');