1 回答
TA贡献1824条经验 获得超5个赞
试试这个
var v;
function link(){
v=document.querySelectorAll('[style*="background:black;"]');
v.forEach(function(value){
value.style.backgroundColor = "red";
});
}
.box1{
height:200px;
width:200px;
border:2px solid green;
font-size:25px;
color:white;
}
<html>
<head>
<link rel="stylesheet" href="filter.css" />
</head>
<body>
<div style="background:black; height:100px; width:100px;" id="div1"></div>
<div style="background:blue; height:100px; width:100px;"></div>
<div style="background:black; height:100px; width:100px;"></div>
<div class="box1" style="background:black;"> css styled box</div>
<button onclick="link()" style="height:20px; width:50px;">Click </button>
</body>
</html>
添加回答
举报