Rumah >hujung hadapan web >html tutorial >学习JS遇到的问题_html/css_WEB-ITnose
关于document.body.innerHTML
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>tit</title> <style type="text/css"> div{width: 30px;height: 30px;font-size: 12px;color: #fff;background: red;line-height: 30px;text-align: center;position: absolute;} </style> <script type="text/javascript"> window.onload=function(){ var oDiv=document.getElementsByTagName('div'); var oBtn=document.getElementsByTagName('input'); var m=0; oBtn[0].onclick=function(){ for(i=0;i<9;i++){ document.body.innerHTML+='<div>'+i+'</div>'; } } } </script></head><body> <input type="submit"value='按钮' name=""></body></html>
再次点击按钮,按钮无效的原因: