请老师检查

来源: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回答

好帮手慕久久

2021-09-17

同学你好,代码正确,很棒!

祝学习愉快!

0

前端工程师

前端入门如同写字,如果你不知道从哪开始,那就选择前端(含Vue3.x,React17,TS)

20327 学习 · 17877 问题

查看课程

相似问题