2016-09-17 1 views
0

私は、テキストエリアをエディタに変換するためにcodemirrorを使用していますが、以前の入力選択フィールド選択のベースでtextareaフィールドを有効にする必要があります。どうしたらいいですか?ここでCodemirror textarea editorは以前の選択時にのみ有効にする必要があります

コードスニペットです:

テキストエリアのフィールド:

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

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

するだけで、あなたにいくつかのヒントを与えるために:

のように、関数内でごCodeMirrorコードを置く:

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

とするとき選択フィールドの変更機能を実行します。

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

ありがとうございます! –

関連する問題