CodeMirror textarea.getAttribute不是mvc3应用程序中的函数错误 [英] CodeMirror textarea.getAttribute is not a function error in mvc3 application

查看:77
本文介绍了CodeMirror textarea.getAttribute不是mvc3应用程序中的函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET MVC 3应用程序中使用CodeMirror,
CodeMirror的版本为最新版本(2.34)

I'm using CodeMirror in my ASP.NET MVC 3 application, CodeMirror's version is up to date(2.34)

我的 textarea 看起来像这样:

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

我这样使用CodeMirror:

I use CodeMirror like this:

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

其中 $ code

var $code = jQuery('.nffp-code', $root);

在页面加载后出现此错误:

And after page load I have this error:


TypeError:textarea.getAttribute不是函数

codemirror.js

第2209行

textarea.getAttribute(自动对焦)!= null&& hasFocus == document.body;

TypeError: textarea.getAttribute is not a function
codemirror.js
Line 2209
textarea.getAttribute("autofocus") != null && hasFocus == document.body;

我使用本手册来使用CodeMirror:
手册

I used this manual for using CodeMirror: manual

即使以为我是JS的傻瓜,我想很难做到这一点,但我还是这么做了。

Even thought, I'm a total noob in JS, I guess it's hard to do it wrong, still I did.

是否有解决问题的方法?

Any Ideas how to fix the problem?

推荐答案

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

You need to use document.getElementById() instead of the jQuery lookup.

这篇关于CodeMirror textarea.getAttribute不是mvc3应用程序中的函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆