【发布时间】:2014-08-01 08:44:56
【问题描述】:
我一直在尝试向javascript 工具添加一些功能,我需要突出显示codemirror 中的一行。我正在使用AngularJs。
首先,我尝试按照教程进行操作
function highlightLine(lineNumber) {
//Line number is zero based index
var actualLineNumber = lineNumber - 1;
//Select editor loaded in the DOM
var myEditor = $("#body_EditorSource .CodeMirror");
//Write the item to the console window, for debugging
console.log(myEditor);
//Select the first item (zero index) just incase more than one found & get the CodeMirror JS object
var codeMirrorEditor = myEditor[0].CodeMirror;
//Write the item to the console window, for debugging
console.log(myEditor[0].CodeMirror);
//Set line CSS class to the line number & affecting the background of the line with the css class of line-error
codeMirrorEditor.setLineClass(actualLineNumber, 'background', 'line-error');
}
但它不起作用,没有检测到myEditor var...我试过了:
var myEditor = document.getElementById('codeMirrorDiv');
var myEditor = angular.element(document.querySelector((".codeMirrorDiv")));
什么都没有。似乎是什么问题?
【问题讨论】:
标签: javascript angularjs dom codemirror