<!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>
原文地址:https://www.cnblogs.com/randomlee/p/9716409.html
时间: 2024-11-03 05:42:47