Jquery的hover方法让鼠标经过li时背景变色

来源地址:http://itfish.net/article/29790.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>StripingTable</title> 
<script src="jquery-1.1.3.pack.js" type="text/javascript"></script> 
<!--将jQuery引用进来--> 
<script type="text/javascript"> 
$(document).ready(function() { 
$("#orderedlist tbody tr").hover(function() { 
// $("#orderedlist li:last").hover(function() { 
$(this).addClass("blue"); 
}, function() { 
$(this).removeClass("blue"); 
}); 
}); 
</script> 
<style> 
.blue { 
background:#bcd4ec; 

</style> 
</head> 
<body> 
<table id="orderedlist" width="50%" border="0" cellspacing="0" cellpadding="0"> 
<!--用class="stripe"来标识需要使用该效果的表格--> 
<thead> 
<tr> 
<th>姓名</th> 
<th>年龄</th> 
<th>QQ</th> 
<th>Email</th> 
</tr> 
</thead> 
<tbody> 
<tr> 
<td>邓国梁</td> 
<td>23</td> 
<td>31540205</td> 
<td>[email protected]</td> 
</tr> 
<tr> 
<td>邓国梁</td> 
<td>23</td> 
<td>31540205</td> 
<td>[email protected]</td> 
</tr> 
<tr> 
<td>邓国梁</td> 
<td>23</td> 
<td>31540205</td> 
<td>[email protected]</td> 
</tr> 
<tr> 
<td>邓国梁</td> 
<td>23</td> 
<td>31540205</td> 
<td>[email protected]</td> 
</tr> 
<tr> 
<td>邓国梁</td> 
<td>23</td> 
<td>31540205</td> 
<td>[email protected]</td> 
</tr> 
<tr> 
<td>邓国梁</td> 
<td>23</td> 
<td>31540205</td> 
<td>[email protected]</td> 
</tr> 
</tbody> 
</table> 
</body> 
</html>

截图如下:

时间: 2024-08-01 06:34:17

Jquery的hover方法让鼠标经过li时背景变色的相关文章

【jquery】hover方法

方法名称:hover(over, out) 概述:当鼠标移动到一个匹配的元素上面时,会触发指定的第一个函数.当鼠标移出这个元素时,会触发指定的第二个函数. 参数: 1) overFunction 鼠标移到元素上要触发的函数 2) outFunction 鼠标移出元素要触发的函数 例子: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content=&q

CSS实现的鼠标悬浮整行背景变色代码

CSS实现的鼠标悬浮整行背景变色代码:在新闻列表形式的不居中,为了清晰的分辨每一行,一般当鼠标悬浮在一行上的时候,能够实现当前行整行变色,下面就通过代码实例简单介绍一下如何实现此效果,代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/

jquery的ajax方法在无返回值时的返回值类型设定

2013-12-07 19:15:29|  分类: Web前端 |  标签:html  |举报|字号 订阅 $.ajax({ type: "post", url: "index.php", data: "id="+uid, dataType:"json", success : function(){ alert(1); }, error: function(){ alert(0); } }); 在jquery的ajax方法中,

jQuery的hover()方法(笔记)

因为mouseover和mouseout经常一起写,所以出现了hover() hover(function(){},function(){});第一个参数为鼠标移入运行的函数,第二个为鼠标离开运行的函数 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><ht

Jquery之table中根据行选中,进行背景变色和radio选中

实现功能:点击列表中的某一行,然后当前行会变成其他颜色,并且其中的radio会被选中. <%@ page language="java" contentType="text/html; charset=UTF-8"     pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() 

jQuery用unbind方法去掉hover事件及其他方法介绍

近日项目开发十分的繁忙,其中一个需求是实现响应式导航.(响应式的问题我们在css相关的博客中再交流) 大家都知道导航是需要下来菜单效果的,必然就会用到 jQuery的 hover() 方法.若是导航放在ipad中,自然hover()就没有什么意义了.那该如何取消hover()并添加touch事件呢? 今天遇到jquery需要去掉hover的问题,原以为直接unbind(“hover”)就可以搞定,可是搞了半天都报错. 原因其实很简单,hover并不是事件.打开参考手册,hover其实由 mous

关于jquery的load方法重复绑定的问题

今天在使用jquery的$.load()方法加载外部文件时,发现竟然触发了两次事件,造成数据的重复加载,百度谷歌之后,发现别人给出的解释是这样的: 如果绑定给window对象,则会在所有内容加载后触发,包括窗口,框架,对象和图像.如果绑定在元素上,则当元素的内容加载完毕后触发. 注意:只有当在这个元素完全加载完之前绑定load的处理函数,才会在他加载完后触发.如果之后再绑定就永远不会触发了.所以不要在$(document).ready()里绑定load事件,因为jQuery会在所有DOM加载完成

Jquery hover方法使用及 mouseenter与mouseleave和 mouseover与mouseout的区别

定义和用法 hover() 方法规定当鼠标指针悬停在被选元素上时要运行的两个函数. jQuery 1.7 版本前该方法触发 mouseenter 和 mouseleave 事件. jQuery 1.8 版本后该方法触发 mouseover和 mouseout事件. 语法 $(selector).hover(inFunction,outFunction)//inFunction 必需,规定 mouseover 事件发生时运行的函数:outFunction 可选,规定 mouseout 事件发生时运

jQuery hover() 方法 -《狗嗨默示录》-

jQuery hover() 方法 实例 当鼠标指针悬停在上面时,改变 <p> 元素的背景颜色: $("p").hover(function(){    $("p").css("background-color","yellow");},function(){    $("p").css("background-color","pink");}); 尝试一