JS的简单小应用:点击切换图片之开关灯
程序员文章站
2022-10-30 18:32:09
js的简单小应用:点击切换图片之开关灯
...
js的简单小应用:点击切换图片之开关灯
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <script> function toggle() { var test1 = document.getelementbyid('test1'); if(test1.src.indexof('on') >= 0) { test1.src = 'off.png'; } else { test1.src = 'on.png'; } } </script> </head> <body> <img id="test1" src="on.png" alt="" onclick="toggle();" /> </body> </html>
关灯:
点击后,开灯: