列表

详情


JS28. Map保存节点

描述

请补全JavaScript代码,要求将页面中的"p"标签以键名的形式保存在Map对象中,键名所对应的键值为该"p"标签的文字内容。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1685ms, 内存消耗: 77828KB, 提交时间: 2022-02-10

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<p>1</p>\n        <script type=\"text/javascript\">\n            const _elementKey = () => {\n                // 补全代码\n                let p = document.querySelector('p')\n                return new Map([[p,p.innerText]])\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1735ms, 内存消耗: 77796KB, 提交时间: 2022-01-01

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<p>1</p>\n        <script type=\"text/javascript\">\n            const _elementKey = () => {\n                // 补全代码\n                let key = document.querySelector('p');\n                let value = key.textContent;\n                let m = new Map();\n                m.set(key,value);\n                return m;\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1735ms, 内存消耗: 77844KB, 提交时间: 2021-12-27

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<p>1</p>\n        <script type=\"text/javascript\">\n            const _elementKey = () => {\n                // 补全代码\n                let p = document.querySelector('p')\n                let entry = [[p,p.textContent]]\n                return new Map(entry)\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1736ms, 内存消耗: 77772KB, 提交时间: 2022-01-24

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<p>1</p>\n        <script type=\"text/javascript\">\n            const _elementKey = () => {\n                // 补全代码\n                const p = document.querySelector('p')\n                return new Map().set(p,p.innerText)\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1736ms, 内存消耗: 77860KB, 提交时间: 2021-12-09

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<p>1</p>\n        <script type=\"text/javascript\">\n            const _elementKey = () => {\n                // 补全代码\n                var p = document.getElementsByTagName('p')[0]\n                var m = new Map()\n                m.set(p, p.innerText)\n                return m\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题