0

我正在使用 codemirror 将我的 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 函数:

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

1 回答 1

1

只是给你一些提示:

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

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

并在选择字段更改时执行功能:

      .............
        case 'true':
               $('textarea[name="notfound_template_content"]').attr("disabled", false);
               Create_Codemirror_textarea()
        case 'false':
               ................
于 2016-09-20T08:24:01.223 回答