请老师检查
来源:3-10 编程练习
慕UI4313976
2021-09-17 00:34:46
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<p>1</p>
<p>2</p>
<p>3</p>
<script>
const [p1, p2, p3] = document.querySelectorAll("p");
const m = new Map([
[
p1,
new Map([
["color", "red"],
["backgroundColor", "yellow"],
["fontSize", "40px"],
]),
],
[
p2,
new Map([
["color", "green"],
["backgroundColor", "pink"],
["fontSize", "40px"],
]),
],
[
p3,
new Map([
["color", "blue"],
["backgroundColor", "orange"],
["fontSize", "40px"],
]),
],
]);
m.forEach((attrObj, element) => {
console.log(attrObj);
attrObj.forEach((innerValue,innerAttr)=>{
element.style[innerAttr] = innerValue;
})
});
</script>
</body>
</html>1回答
同学你好,代码正确,很棒!
祝学习愉快!