先看看这个使用jQuery做的双色表格的效果:
这个双色表格看上去应该觉得挺专业的,不过它用jQuery实现的确很简单。
第一步:
写好css。加上背景色*/
}
tr.over td {
background:#bcd4ec; /这个将是鼠标高亮行的背景色/
}
第二步:
写jQuery页面加载事件:添加class值为alt
$(".stripe tr:even").addClass("alt");
$(".stripe tr").mouSEOver(function(){//如果鼠标移到class为stripe的表格的tr上时,执行函数
$(this).addClass("over");}).mouSEOut(function(){//给这行添加class值为over,并且当鼠标一出该行时执行函数
$(this).removeClass("over");
})
});
上面的鼠标悬浮事件采用了jQuery的链式操作,本来是应该这么写的:
SEOver(function(){
$(this).addClass("over");})
$(".stripe tr").mouSEOut(function(){
$(this).removeClass("over"); })
但上面的的代码却写成了这样:
SEOver(function(){
$(this).addClass("over");}).mouSEOut(function(){
$(this).removeClass("over");})
在jQuery中,执行完mouSEOver或mouSEOut等方法之后,它会返回当前的操作对象,所以可以采用jQuery的链式操作。
下面把完整的jsp代码贴出来MyJsp.jsp:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
jQuery用几分钟时间搞定双色表格