单击循环简单练习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>鼠标循环单机</title> <style> #mydiv{ height: 50px; line-height: 50px; background-color:#ccc; } </style> </head> <body> <div id="mydiv"></div> <script> // 给一个变量从0开始,单数点击为xxx,然后双数次点击为xxx; var myDiv = document.getElementById("mydiv"); var i = 0; myDiv.onclick = function(){ if(i%2 == 0){ this.style.backgroundColor = "red"; }else{ this.style.backgroundColor = "#ccc"; } i++; }; </script> </body> </html>