【问题标题】:Codemirror textarea editor need to enable only on previous selectionCodemirror textarea 编辑器只需要在之前的选择上启用
【发布时间】:2016-09-17 05:59:21
【问题描述】:

我正在使用 codemirror 将我的 textarea 转换为编辑器,但还有一个问题是我需要仅在先前输入选择字段选择的基础上启用该 textarea 字段。我该怎么做?

这里是代码sn-ps:

文本区域字段:

<textarea cols="1200" rows="10" id="nfTextArea" disabled="disabled" class="form-control" name="notfound_template_content"></textarea>

上一个选择字段:

<div class="field_group html1"><label title="HTML."> Include 404 Template </label>
                                            <select name="nf_template" class="form-control" value="" type="text" onchange="notFound()">
                                                <option value="other"> Choose...</option>
                                                <option value="true"> Yes </option>
                                                <option value="false"> No </option>
                                            </select>
                                            <span class="help-block"> Select yes if you want to create 404 Template.</span>
                                        </div>

基于选择启用文本区域字段的Javascript函数:

 //function to enable 404 template
    function notFound(){
        var $content = $('select[name="404_template"] option:selected').val();
        switch ($content) {
            case 'true':
                $('textarea[name="notfound_template_content"]').attr("disabled", false);
                break;
            case 'false':
                $('textarea[name="notfound_template_content"]').attr("disabled", true);
            default:
                $('textarea[name="notfound_template_content"]').attr("disabled", false);
                break;
        }
    }

代码镜像功能:

var myCodeMirror = CodeMirror.fromTextArea(nfTextArea,{
lineNumbers: true,
mode: 'htmlmixed',
theme : 'monokai',
enterMode: 'keep',
indentUnit: 4,
matchBrackets: true,
gutters: ["CodeMirror-lint-markers", "CodeMirror-linenumbers"],
styleActiveLine: true, /* Addon */
onCursorActivity: function() {
      editor.addLineClass(hlLine, null);
      hlLine = editor.addLineClass(editor.getCursor().line, "CodeMirror-    activeline-background");
   }
});
myCodeMirror.focus();
myCodeMirror.setCursor({line: 3});

【问题讨论】:

    标签: html codemirror ui-codemirror


    【解决方案1】:

    只是给你一些提示:

    将您的 CodeMirror 代码放入函数中,例如:

    function Create_Codemirror_textarea(){
       var myCodeMirror = ........
       ....
    }
    
    选择字段更改时

    并执行功能:

          .............
            case 'true':
                   $('textarea[name="notfound_template_content"]').attr("disabled", false);
                   Create_Codemirror_textarea()
            case 'false':
                   ................
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多