使用js编写一个开关灯案例?

    科技2022-08-10  92

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <button>按钮</button> <script> var but = document.querySelector('button') but.onclick = function () { // 事件发生时要执行的代码 var h5 = document.querySelector('html') if (h5.style.backgroundColor == 'white') { h5.style.backgroundColor = 'black' } else { h5.style.backgroundColor = 'white' } } </script> </body> </html>

    Processed: 0.013, SQL: 8