当前位置:网站首页>DOM light switch case

DOM light switch case

2022-07-03 21:37:00 Rice field prospector

<body>
    <img src="./off.gif" id="light">
    <script> //1. Get the picture object  var light = document.getElementById("light"); var flag = false;// It means that the light is off  //2. Bind click event  light.onclick = function(){
       if(flag){
       // Judge if the light is on, then turn it off  light.src = "./on.gif" flag = false; }else{
       // Judge if the light is off, turn it on  light.src = "./off.gif" flag = true; } } </script>
</body>

原网站

版权声明
本文为[Rice field prospector]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202142308434111.html