Codemirror textarea编辑器只需要在以前的选择上启用

时间:2016-09-17 05:59:21

标签: html codemirror ui-codemirror

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

以下是代码段:

Textarea字段:

<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函数在选择的基础上启用textarea字段:

 //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;
        }
    }

Codemirror功能:

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});

1 个答案:

答案 0 :(得分:1)

只是给你一些提示:

将CodeMirror代码放在函数中,例如:

function Create_Codemirror_textarea(){
   var myCodeMirror = ........
   ....
}

并在选择字段更改时执行函数:

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