js之获取html标签的值
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div> <input id='user' type='text' /> //绑定getData函数 <input type="button" value="提交" onclick="getData();"/> <div id="i1">helloworld</div> </div> </body> <script> function getData() { //获取输入框的文本 var i=document.getElementById('user'); alert(i.value); console.log(i.value) } //获取div的文本内容 var tag=document.getElementById('i1') var content=tag.innerText console.log(content) </script> </html>