JavaScript习题(在html创建一个绿色小方块,鼠标移入变黄色,移除变红色)

    技术2022-07-11  137

    以下是HTML页面的代码:

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>中国的流浪猫</title> <link rel="stylesheet" type="text/css" href="regality.css"> </head> <body> <div style="width: 200px;height: 200px;background-color: green;"> </div> <script type="text/javascript" src="lesson.js"> </script> </body> </html>

    以下是JavaScript页面的代码:

    var div = document.getElementsByTagName('div')[0]; div.onmouseenter = function () { this.style.backgroundColor = 'yellow' } div.onmouseleave = function(){ this.style.backgroundColor = 'red' }
    Processed: 0.020, SQL: 9