簡體   English   中英

Uncaught ReferenceError: CodeMirror 未定義,盡管我已經包含了所有內容。 如何美化textarea中的JSON和XML

[英]Uncaught ReferenceError: CodeMirror is not defined although I have included everything. How to beautify the JSON and XML in textarea

I tried some of the available answers related to the same but none worked hence posting the same

我正在嘗試使用 CodeMirror 在 textarea 中格式化 JSON 和 XML 代碼,因此我下載了 CodemIrror zip 文件並粘貼到我的項目文件夾中。 文件夾結構看起來像這樣。

Views
  -codemirror (directory with all the folders related to it including lib)
  -index.html

在我的ìndex.html ,我包含了代碼鏡像:

    <link rel="stylesheet" type="text/css" href="codemirror/lib/codemirror.css">
    <script type="text/javascript" src="codemirror/lib/codemirror.js"></script>
    <script type="text/javascript" src="codemirror/mode/clike/clike.js"></script>
    <script type="text/javascript" src="codemirror/mode/javascript/javascript.js"></script>
    <script type="text/javascript" src="codemirror/mode/xml/xml.js"></script>

我的 Index.html 中的文本區域也為:

<div class="col-md-8">
   <h5>Test Events in XML :</h5>
   <textarea stryle="height: 400px;" class="form-control" id="xmldata" ng-model="xmldata"></textarea>
</div>

在我的 Javascript 文件中,我只是嘗試使用 codemirror 將行號添加到 Textarea 但由於某種原因它失敗了:

var editor = CodeMirror.fromTextArea(xmldata, {
    lineNumbers: true
  });

當我運行代碼時,我的瀏覽器控制台中出現以下錯誤:

homeScript.js:115 Uncaught ReferenceError: CodeMirror is not defined
    at homeScript.js:115

如何使用 CodeMirror 美化 Textarea 中存在的 XML 和 JSON 數據

你確定"xmldata"是一個元素的句柄嗎? 正確的代碼如下所示:

var myTextArea=document.getElementById("xmldata");
CodeMirror.fromTextArea(myTextArea);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM