JavaScript 点击按钮div变透明
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> div { width: 300px; height: 200px; background-color: pink; } </style> </head> <body> <div id="dv"></div> <input type="button" id="bt" value="变透明"/> <script src="common.js"></script> <script> my$("bt").onclick = function () { var opacity = 10; var timeId = setInterval(function () { opacity--; if (opacity <= 0) { //清理定时器 clearInterval(timeId); } my$("dv").style.opacity = opacity / 10; }, 200) }; </script> </body> </html>