在 HTML 中滑鼠指標移過元素時如何執行指令碼?
在 HTML 中,當滑鼠指標移過元素時,onmouseover 屬性被觸發。
示例
你可以嘗試執行以下程式碼來實現 onmouseover 屬性 −
<!DOCTYPE html> <html> <body> <h3 id = "myid" onmouseover = "display()"> This is demo heading. </h3> <p>Keep the mouse cursor on the heading to change the color.</p> <script> function display() { document.getElementById("myid").style.color = "red"; } </script> </body> </html>
廣告