题解 | #单向绑定#
单向绑定
https://www.nowcoder.com/practice/728b83e2b9b948dbababcc4a494eefc3
<!DOCTYPE html> <html> <head> <meta charset=utf-8> </head> <body> <input id="input" type="text" /> <span id="span"></span> <script type="text/javascript"> // 补全代码 document.getElementById("input").onchange = function(){ document.getElementById("span").innerHTML = this.value } </script> </body> </html>
该题主要考察的是单向绑定:DOM 可以首先使用 getElementById 获取id = “input”如果改变onchange 获取到的值 再赋值给id= “span”,document.getElementById("span").innerHTML = this.value