我想基于类名称“ cls-editable”更改div背景颜色,javascript使用它来查找元素,然后将editable属性设置为“ true”或“ false”。
可编辑时,背景为黄色。否则,它是白色的。
HTML
<div class='cls-editable'>
Hello
</div>
CSS:
.cls-editable,[contenteditable="true"] {
background-color: yellow;
}
.cls-editable,[contenteditable="false"] {
background-color: white;
}
Javascript:
if (this.checkStatus) {
$('.dirs_row').children('.cls-editable').each(function () {
$(this).attr('contenteditable','true');
});
} else {
$('.dirs_row').children('.cls-editable').each(function () {
$(this).attr('contenteditable','false');
});
}
但是,它不起作用。 CSS怎么了?