【问题标题】:How do I deactivate Bootstrap-wysihtml5 jquery editor instance?如何停用 Bootstrap-wysihtml5 jquery 编辑器实例?
【发布时间】:2015-02-25 20:40:23
【问题描述】:

我正在使用 Bootstrap-wysihtml5 jquery 插件 (https://github.com/jhollingworth/bootstrap-wysihtml5/) 将文本区域转换为所见即所得。我希望能够通过单击 2 个按钮来激活和停用编辑器,到目前为止我可以显示编辑器,请你告诉我如何停用编辑器并只留下 textarea 及其值。我的代码如下:-

HTML

<textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>

<input type="button" id="button1" value="Show Editor"> 
<input type="button" id="button2" value="Hide Editor">

脚本

$("#button1").click(function(){
$('textarea').wysihtml5();
});

$("#button2").click(function(){
// this is where i'm stuck
});

谢谢

【问题讨论】:

    标签: wysihtml5


    【解决方案1】:

    几行自定义 JS 代码。我想他们可以帮助你。

    var content = $('#content');
    var contentPar = content.parent()
    contentPar.find('.wysihtml5-toolbar').remove()
    contentPar.find('iframe').remove()
    contentPar.find('input[name*="wysihtml5"]').remove()
    content.show()
    

    【讨论】:

    • 请解释更改以及它们为何有用。
    • 通过这个你可以从你的文本区域中删除编辑器。 '#content' 是获取文本区域的选择器。上一篇文章对我没有帮助,因为它只是隐藏,但没有禁用 wysihtml5,我可以通过 ctrl+b 保存粗体等。
    【解决方案2】:

    我在尝试禁用/隐藏工具栏和编辑器时遇到了同样的问题,并且幸运地使用了以下命令(禁用编辑器)。我正在使用版本 wysihtml5-0.3.0_rc2.js)

    $('#editorId').data('wysihtml5').editor.composer.disable();
    $('#editorId').data('wysihtml5').editor.composer.enable();
    

    或(隐藏编辑器)

    $('#editorId').data('wysihtml5').editor.composer.hide();
    $('#editorId').data('wysihtml5').editor.composer.show();
    

    要对工具栏执行相同操作,请执行以下操作以隐藏/显示(找不到禁用工具栏的 wat):

    $('#editorId').data('wysihtml5').editor.toolbar.hide();
    $('#editorId').data('wysihtml5').editor.toolbar.show();
    

    【讨论】:

    • 嘿佩德罗,你能解释一下如何完全删除编辑器吗?我想要做的是,将它用作内联编辑器。假设我有两个段落,shift+click 在第一段上只打开第一段的编辑器。现在,如果用户 shift+单击第二段,我想完全删除第一段的编辑器,只为第二段打开它。我不知道我是否能够很好地沟通,但你还是会明白的。提前致谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多