如何在 Summernotes 中禁用编辑? [英] How to Disable Editing in Summernotes?

查看:59
本文介绍了如何在 Summernotes 中禁用编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 summernotes 组件,我想要做的是阻止用户添加字符 if s(他) 超过 2000 个字符,但我不知道如何停止输入事件.

I am using summernotes component and what I want to do is I want to stop the user from adding characters if s(he) exceeds 2000 Chars but I couldn't figure out how to stop typing event.

我正在做的事情如下:

 $(".note-editable").each(function(){
           $(this).on("keyup", function(){
                var cc = $(this).text().length;
                var arr = $(this).next().attr("class").split('_');
                var q = "q"+arr[0];
                var maxChar = arr[2];
                var textarea = $('*[name^="'+q+'"]');
                var diffChar = parseInt(maxChar - cc);
               
                if(diffChar >= 0)
                {
                    $(this).next().text(diffChar + " Remaining out of " + maxChar);
                }
                else
                {
                    $(this).next().text("0 Remaining out of " + maxChar);
                    
                    //$(textarea).prop('disabled', true);
                    $(this).text($(this).text().slice(0,diffChar));
                }
           });
        });

任何想法如何做到这一点,我不想禁用光标或破坏summernote ..我想让用户觉得他仍然可以编辑但如果文本不会输入任何内容超过 2000 个字符.

Any Idea how to do that, I don't want to disable the cursor or destroy the summernote .. I want to let the user feel that (s)he can still edit but it won't type anything if the text exceeds 2000 chars.

谢谢!!

推荐答案

这个链接 来自他们的官方文档.

Look at this link from their official document.

基本上,您需要做的是:

Basically, what you need to do is:

您可以通过 API 禁用编辑器.

You can disable editor by API.

$('#summernote').summernote('disable');

如果您想再次启用编辑器,请使用 enable 调用 API.

If you want to enable editor again, call API with enable.

$('#summernote').summernote('enable');

现在,您可以做的是,在您自己的代码逻辑/算法中使用这些 API 调用来获得所需的效果.

Now, what you can do is, use these API calls in your own code logic/algorithms to get the desired effect.

我知道这是一个老问题,但希望这会有所帮助.

I know its an old question, but hope this helps.

这篇关于如何在 Summernotes 中禁用编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆