欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用jQuery5分鐘快速搞定雙色表格的簡(jiǎn)單實(shí)例

 更新時(shí)間:2016年08月08日 09:54:46   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇使用jQuery5分鐘快速搞定雙色表格的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

先看看這個(gè)使用jQuery做的雙色表格的效果:

這個(gè)雙色表格看上去應(yīng)該覺得挺專業(yè)的,不過(guò)它用jQuery實(shí)現(xiàn)的確很簡(jiǎn)單。

第一步:寫好css。

<style type="text/css"> 
th { /*表頭樣式*/ 
  background:#0066FF; 
  color:#FFFFFF; 
  line-height:20px; 
  height:30px; 
} 
td { 
  padding:6px 11px; 
  border-bottom:1px solid #95bce2; 
  vertical-align:top; 
  text-align:center; 
} 
td * { 
  padding:6px 11px; 
} 
tr.alt td { 
  background:#ecf6fc; /*這行將給所有的tr加上背景色*/ 
} 
 
tr.over td { 
  background:#bcd4ec; /*這個(gè)將是鼠標(biāo)高亮行的背景色*/ 
} 
</style>

第二步:寫jQuery頁(yè)面加載事件:

<script type="text/javascript"> 
	$(function(){
			//給class為stripe的表格的偶數(shù)行添加class值為alt 
	  $(".stripe tr:even").addClass("alt"); 
			$(".stripe tr").mouseover(function(){//如果鼠標(biāo)移到class為stripe的表格的tr上時(shí),執(zhí)行函數(shù) 
    $(this).addClass("over");}).mouseout(function(){//給這行添加class值為over,并且當(dāng)鼠標(biāo)一出該行時(shí)執(zhí)行函數(shù)
     $(this).removeClass("over");
   })
	}); 
</script> 

上面的鼠標(biāo)懸浮事件采用了jQuery的鏈?zhǔn)讲僮?,本?lái)是應(yīng)該這么寫的:

$(".stripe tr").mouseover(function(){ 
  $(this).addClass("over");}) 
$(".stripe tr").mouseout(function(){ 
  $(this).removeClass("over"); })

但上面的的代碼卻寫成了這樣:

$(".stripe tr").mouseover(function(){ 
    $(this).addClass("over");}).mouseout(function(){ 
     $(this).removeClass("over");})

在jQuery中,執(zhí)行完mouseover或mouseout等方法之后,它會(huì)返回當(dāng)前的操作對(duì)象,所以可以采用jQuery的鏈?zhǔn)讲僮鳌?/p>

下面把完整的jsp代碼貼出來(lái)MyJsp.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%>">
 <title>jQuery用幾分鐘時(shí)間搞定雙色表格</title>
	<script type="text/javascript" src="mybag/jquery-1.4.2.min.js"></script>
	<script type="text/javascript"> 
	$(function(){
			//給class為stripe的表格的偶數(shù)行添加class值為alt 
	  $(".stripe tr:even").addClass("alt"); 
			$(".stripe tr").mouseover(function(){//如果鼠標(biāo)移到class為stripe的表格的tr上時(shí),執(zhí)行函數(shù) 
    $(this).addClass("over");}).mouseout(function(){//給這行添加class值為over,并且當(dāng)鼠標(biāo)一出該行時(shí)執(zhí)行函數(shù)
     $(this).removeClass("over");
   })
	}); 
	</script> 
	<style type="text/css"> 
	th { 
	  background:#0066FF; 
	  color:#FFFFFF; 
	  line-height:20px; 
	  height:30px; 
	} 
	td { 
	  padding:6px 11px; 
	  border-bottom:1px solid #95bce2; 
	  vertical-align:top; 
	  text-align:center; 
	} 
	td * { 
	  padding:6px 11px; 
	} 
	tr.alt td { 
	  background:#ecf6fc; /*這行將給所有的tr加上背景色*/ 
	} 
	 
	tr.over td { 
	  background:#bcd4ec; /*這個(gè)將是鼠標(biāo)高亮行的背景色*/ 
	} 
	</style>
 </head>
 
<body> 
<!--用class="stripe"來(lái)標(biāo)識(shí)需要使用該效果的表格--> 
<table class="stripe" width="50%" border="0" cellspacing="0" cellpadding="0"> 
<thead> 
 <tr> 
 <th>姓名</th> 
 <th>年齡</th> 
 <th>QQ</th> 
 <th>Email</th> 
 </tr> 
</thead> 
<tbody> 
 <tr> 
 <td>李曉紅</td> 
 <td>24</td> 
 <td>859855***</td> 
 <td>859855***@qq.com</td> 
 </tr> 
 <tr> 
 <td>云天河</td> 
 <td>18</td> 
 <td>123456789</td> 
 <td>123456789@qq.com</td> 
 </tr> 
 <tr> 
 <td>柳夢(mèng)璃</td> 
 <td>18</td> 
 <td>987654321</td> 
 <td>987654321@qq.com</td> 
 </tr> 
 <tr> 
 <td>韓菱紗</td> 
 <td>18</td> 
 <td>888888888</td> 
 <td>888888888@qq.com</td> 
 </tr> 
 <tr> 
 <td>玄霄</td> 
 <td>58</td> 
 <td>123456</td> 
 <td>123456@qq.com</td> 
 </tr> 
 <tr> 
 <td>土靈珠</td> 
 <td>1000</td> 
	<td>-10000</td> 
 <td>-10000@qq.com</td> 
 </tr> 
</tbody> 
</table> 
<p>怎么樣?jQuery就是這么牛x.</p> 
</body>
</html>

以上這篇使用jQuery5分鐘快速搞定雙色表格的簡(jiǎn)單實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論