代码如下所示:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="Content-Language" content="zh-cn" /> <title>输入框</title> </head> <body> <form> <input id="input" type="text" placeholder="请输入你的姓名" /> </form> <button onclick="btn()">测试</button> <div id="html"></div> <script> var x= document.getElementById("input")//获取输入框元素 var y= document.getElementById("html") //获取id为html的元素 function btn(){ y.innerHTML = x.value; //将输入框的值赋给div标签 } </script> </body> </html> 实现效果如下图所示: