gpt4 book ai didi

css - 如何根据类名和 contenteditable 值切换 div 背景颜色

转载 作者:太空宇宙 更新时间:2023-11-03 22:12:15 25 4
gpt4 key购买 nike

我想根据类名“cls-editable”更改 div 背景颜色,javascript 使用它来查找元素,然后将可编辑属性设置为“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 有什么问题?

最佳答案

试试这个

CSS

.cls-editable[contenteditable="true"] {
background-color: yellow;
}

.cls-editable[contenteditable="false"] {
background-color: white;
}

输出

enter image description here

关于css - 如何根据类名和 contenteditable 值切换 div 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58761905/

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