gpt4 book ai didi

javascript - Angular 和代码镜像

转载 作者:行者123 更新时间:2023-12-03 12:08:23 26 4
gpt4 key购买 nike

我一直在尝试向 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")));

什么也没有。问题出在哪里?

最佳答案

该函数名为 addLineClass

关于javascript - Angular 和代码镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25076227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com