循环
white循环:
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> var i=0; while(i<5){ alert(i); i=i+1; } </script> </head> <body> </body> </html>
for循环:
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> for(var i=0;i<5;i=i+1) { alert(i); } </script> </head> <body> </body> </html>
if循环:
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style type="text/css"> #div1 { width: 100px; height:100px; background: red; display: none; } </style> <script> function showhide(){ var odiv=document.getElementById('div1'); if(odiv.style.display=='block') { odiv.style.display='none'; } else{ odiv.style.display='block'; } } </script> </head> <body> <input type="button" value="显示隐藏" onClick="showhide()" /> <div id="div1"> </div> </body> </html>
欢迎访问每天进步网:https://meitianjinbu.cn/