列表

详情


FED53. 阻止默认事件

描述

请补全JavaScript函数,要求在点击id为"checkbox"的复选框时不会取消勾选状态。
注意:需要自行获取input元素。

原站题解

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

{"css":"","js":"","html":"<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n        <form>\n            <label>牛客会陪伴大家</label>\n            <input id=\"checkbox\" type=\"checkbox\" checked />\n        </form>\n    </body>\n    <script type=\"text/javascript\">\n        // 补全代码\n       let cbox=document.getElementById('checkbox')\n        cbox.addEventListener('click',(e)=>{\n            e.preventDefault()\n        })\n    </script>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n        <form>\n            <label for=\"checkbox\">牛客会陪伴大家</label>\n            <input id=\"checkbox\" type=\"checkbox\" checked />\n        </form>\n    </body>\n    <script type=\"text/javascript\">\n        // 补全代码\n        document.getElementById('checkbox').onclick = function(){\n            return false;\n        }\n    </script>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n        <form>\n            <label>牛客会陪伴大家</label>\n            <input id=\"checkbox\" type=\"checkbox\" checked />\n        </form>\n    </body>\n    <script type=\"text/javascript\">\n        // 补全代码\n        \n        const cbox = document.getElementById('checkbox')\n        cbox.onclick = function (e) {\n            e.preventDefault()\n        }\n    </script>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n        <form>\n            <label>牛客会陪伴大家</label>\n            <input id=\"checkbox\" type=\"checkbox\" checked />\n        </form>\n    </body>\n    <script type=\"text/javascript\">\n        // 补全代码\n         let inp = document.querySelector('input');\n         inp.addEventListener('click', function (e) {\n            e.preventDefault()\n          })\n    </script>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n        <form>\n            <label>牛客会陪伴大家</label>\n            <input id=\"checkbox\" type=\"checkbox\" checked />\n        </form>\n    </body>\n    <script type=\"text/javascript\">\n        // 补全代码\n        let chbox = document.getElementById('checkbox');\n        chbox.onclick = (e) => e.preventDefault()\n    </script>\n</html>","libs":[]}

上一题