Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 代码镜像-使给定行完全变灰_Javascript_Jquery_Html_Css_Codemirror - Fatal编程技术网

Javascript 代码镜像-使给定行完全变灰

Javascript 代码镜像-使给定行完全变灰,javascript,jquery,html,css,codemirror,Javascript,Jquery,Html,Css,Codemirror,我正在使用代码镜像,我正在尝试使给定的行完全变灰(因此它看起来像是代码编辑器中的注释)。到目前为止,我已经想到了这个: editorDiv = this; var editor = CodeMirror(function(elt) { editorDiv.parentNode.replaceChild(elt, editorDiv); }, { value: "function myScript(){\n\treturn 100; \n}\n", lineNumbers

我正在使用代码镜像,我正在尝试使给定的行完全变灰(因此它看起来像是代码编辑器中的注释)。到目前为止,我已经想到了这个:

editorDiv = this;

var editor = CodeMirror(function(elt) {
  editorDiv.parentNode.replaceChild(elt, editorDiv);
}, {
  value:       "function myScript(){\n\treturn 100; \n}\n",
  lineNumbers: true,
  readOnly:    "nocursor",
  theme:       "monokai"
});

console.log(editor);

var line = editor.getLineHandle(1);
console.log(line);

editor.addLineClass(line, "text", "greyed-out");
假设我希望
返回100要灰显的行(即编辑器中的第2行和API中的第1行)。我的想法是将
灰显的
类添加到此行,并使该类类似于:

.greyed-out { color: grey; }
但是,这不起作用,因为代码镜像中的其他类具有更高的优先级,并覆盖灰显的

我不确定是否有一种特定的方法通过CodeMirror的API实现这一点,或者有一种通用的方法从更高优先级的类中删除不需要的属性


有人能帮我一下吗?

在这种情况下,你可以使用
!重要信息

.greyed-out { color: grey !important; }

但是,应避免使用,并仅在必要时使用。您还可以通过扩展选择器来增加样式的特定性。

超越另一个类的规则的最佳方法是赋予选择器更高的特定性,例如:

#container.foo list li.greed out{color:grey;}
或者,您可以使用
!重要提示
,但这被视为不良做法,应尽可能避免

.greyed out{color:grey!重要;}