列表

详情


JS4. 单向绑定

描述

请补全JavaScript代码,要求每当id为"input"的输入框值发生改变时触发id为"span"的标签内容同步改变。
注意:
1. 必须使用DOM0级标准事件(onchange)

原站题解

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<input id=\"input\" onchange=\"handcnange(this);\" type=\"text\" />\n        <span id=\"span\"></span>\n\n        <script type=\"text/javascript\">\n            // 补全代码\n            function handcnange(obj){\n            document.getElementById('span').innerHTML=obj.value\n            }\n        </script>\n    </body>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<input id=\"input\" type=\"text\" />\n        <span id=\"span\"></span>\n\n        <script type=\"text/javascript\">\n              input =document.querySelector('#input')\n            span =document.getElementById('span')\n            // span.innerHTML=input.value\n            input.onchange=function(){\n                span.innerHTML=input.value\n            }\n        </script>\n    </body>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<input id=\"input\" type=\"text\" />\n        <span id=\"span\"></span>\n\n        <script type=\"text/javascript\">\n            // 补全代码\n            let input1 = document.querySelector('#input')\n            let span1 = document.querySelector('#span')\n            input1.onchange = function(){\n                span1.innerHTML = this.value\n            }\n        </script>\n    </body>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<input id=\"input\" type=\"text\" />\n        <span id=\"span\"></span>\n\n        <script type=\"text/javascript\">\n            // 补全代码\n            var inputDom = document.querySelector('#input');\n            var spanDom = document.querySelector('#span');\n            inputDom.onchange = function(){\n                spanDom.innerText = inputDom.value;\n            }\n        </script>\n    </body>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t<input id=\"input\" type=\"text\"  />\n        <span id=\"span\"></span>\n\n        <script type=\"text/javascript\">\n            // 补全代码\n         let id_input = document.querySelector('#input')\nlet id_span = document.querySelector('#span')\nid_input.onchange = function() {\n    id_span.innerText = this.value\n}\n            \n        </script>\n    </body>\n</html>","libs":[]}

上一题