CodeMirror textarea.getAttribute不是mvc3应用程序中的函数错误

inl*_*nes 7 codemirror razor

textarea的版本是最新的(2.34)

我的TextArea看起来像这样:

@Html.TextAreaFieldFor(s => s.Data.CodeBehind, htmlAttributes: new Dictionary<string, object> { { "class", "textbox codeBehind nffp-code" } })
Run Code Online (Sandbox Code Playgroud)

我像这样使用codemirror:

var a = CodeMirror.fromTextArea($code, {
        lineNumbers: true,
        matchBrackets: true,
        mode: "text/x-csharp"
});
Run Code Online (Sandbox Code Playgroud)

其中$ code是

var $code = jQuery('.nffp-code', $root);
Run Code Online (Sandbox Code Playgroud)

页面加载后我有这个错误:

TypeError:textarea.getAttribute不是函数codemirror.js第2209行textarea.getAttribute("autofocus")!= null && hasFocus == document.body;

我使用本手册来使用codemirror: manual

即便想到,我也$code很难做错,我仍然这样做.

任何想法如何解决这个问题?

小智 5

您需要使用document.getElementById()而不是jQuery查找。