Javaweb 鼠標移入移出表格顏色變化的實現(xiàn)
最近在學(xué)習JavaWeb時,有用到鼠標移動事件,所以今天在這里記錄一個相關(guān)的案例,同時也是對相關(guān)知識的一個鞏固,效果為在鼠標移動到表格對應(yīng)行列時,該行列的背景顏色發(fā)生變化。
效果如下:
其中用到是onmouseover和onmouseou事件t,同時還有一個作用相似的事件叫做onmousemove,所以在這里先對這三種鼠標事件做一個簡單的對比:
- 在時間上:如果兩個事件同時存在,先是onmousemove事件觸發(fā)后,才會觸發(fā)onmouseover事件。
- 在按鈕上:onmousemove和onmouseover都不區(qū)分鼠標按鈕
- 在動作上:onmouseover是在鼠標剛移入?yún)^(qū)域的時候觸發(fā),onmousemove是除了鼠標移入?yún)^(qū)域時觸發(fā)外,鼠標在區(qū)域內(nèi)移動同樣也會觸發(fā)事件。
- 兩者區(qū)別:當鼠標移過當前對象區(qū)域時就產(chǎn)生了onmouseover事件,所以onmouseover事件有個移入移出的過程,當鼠標在當前對象區(qū)域上移動時就產(chǎn)生了onmousemove事件,只要是在對象上移動而且沒有移出對象的,那么就是onmousemove事件。
onmouseout事件則是在鼠標移出對象區(qū)域時觸發(fā)。
搞懂這三者之間的關(guān)系,在進行鼠標經(jīng)過事件的處理時只需使用對應(yīng)的事件觸發(fā)即可:
接下來是對上述事件和效果的代碼:
Jsp部分代碼:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>" rel="external nofollow" > <title>表格顏色變化</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" > --> <script type="text/javascript" src="index.js"></script> </head> <body> <table width = "200" border = "1" align = "center" cellpadding="1" cellspacing="5"> <tr id = "t0"><th>學(xué)校</th><th>專業(yè)</th><th>人數(shù)</th></tr> <tr id = "t1"><th>濟大</th><th>軟件</th><th>2000</th></tr> <tr id = "t2"><th>北大</th><th>機械</th><th>3000</th></tr> <tr id = "t3"><th>浙大</th><th>生物</th><th>4000</th></tr> </table> </body> </html>
Js部分代碼:
onload = function() { var t0 = document.getElementById("t0"); var t1 = document.getElementById("t1"); var t2 = document.getElementById("t2"); var t3 = document.getElementById("t3"); t0.onmouseover = function () { t0.style.backgroundColor = "green"; } t0.onmouseout = function () { t0.style.backgroundColor = "white"; } t1.onmouseover = function () { t1.style.backgroundColor = "red"; } t1.onmouseout = function () { t1.style.backgroundColor = "white"; } t2.onmouseover = function () { t2.style.backgroundColor = "red"; } t2.onmouseout = function () { t2.style.backgroundColor = "white"; } t3.onmouseover = function () { t3.style.backgroundColor = "red"; } t3.onmouseout = function () { t3.style.backgroundColor = "white"; } }
到此這篇關(guān)于Javaweb 鼠標移入移出表格顏色變化的實現(xiàn)的文章就介紹到這了,更多相關(guān)Javaweb 鼠標移入移出表格內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot事件發(fā)布與監(jiān)聽超詳細講解
今天去官網(wǎng)查看spring boot資料時,在特性中看見了系統(tǒng)的事件及監(jiān)聽章節(jié),所以下面這篇文章主要給大家介紹了關(guān)于SpringBoot事件發(fā)布和監(jiān)聽的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-11-11IDEA無法打開Marketplace的三種解決方案(推薦)
這篇文章主要介紹了IDEA無法打開Marketplace的三種解決方案(推薦),本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11java案例實戰(zhàn)之字符串轉(zhuǎn)換為二進制
最近遇到個需求,要求編寫一個程序,從鍵盤錄入一個字符串,將字符串轉(zhuǎn)換為二進制數(shù),下面這篇文章主要給大家介紹了關(guān)于java字符串轉(zhuǎn)換為二進制的相關(guān)資料,需要的朋友可以參考下2023-06-06Java Set簡介_動力節(jié)點Java學(xué)院整理
Set最大的特性就是不允許在其中存放的元素是重復(fù)的。接下來通過本文給大家分享java set常用方法和原理分析,需要的的朋友參考下吧2017-05-05詳解Lombok安裝及Spring Boot集成Lombok
這篇文章主要介紹了詳解Lombok安裝及Spring Boot集成Lombok,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-03-03