innerHTML的用法
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style type="text/css"> #div1 {width: 200px;height: 200px;border: 1px solid black;} </style> </head> <body> <input id="txt1" type="text"> <input id="put1" type="button" value="改文字" /> <br/><br/> <div id="div1"></div> <script> var otxt=document.getElementById('txt1'); var oput=document.getElementById('put1'); var odiv=document.getElementById('div1'); oput.onclick=function() { odiv.innerHTML=otxt.value;/*innerHTML里面就是正常的HTML,可以放上p、h1等*/ } </script> </body> </html>
欢迎访问每天进步网:https://meitianjinbu.cn/