<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script> </head> <body> <div id="setBtn" onclick="setBtn(this);">点我吧aaaaaaaaaaaaaaaa</div> <input type="text" onclick="setBtn2(this);" value="我的名称" /> <script> function setBtn($obj){ console.log($obj.innerHTML = '<span>hello world</span>'); //获取javaScript的内容(包括Html标记) 类似jQuery里面的$(selector).html(); // console.log($obj.innerText = '<span>hello world</span>'); //获取javaScript的内容 类似jQuery里面的$(selector).text(); } function setBtn2($obj){ console.log($obj.value); //获取表单元素的值 类似jQuery里面的$(selector).val(); } </script> </body> </html>
用js获取文本内容和文本框内容
最新推荐文章于 2024-08-22 02:17:51 发布