Jquery之使用parents实例

1

<!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>parents的用法</title> 
<script type="text/javascript" src="jquery-1.1.3.pack.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() {
	$("a").hover(function() {
		$(this).parents("p").addClass("highlight");
	}, function() {
		$(this).parents("p").removeClass("highlight");
	});
});
</script> 
<style>
.highlight {
    background:gray;
	border: 3px dotted #eee;
}
</style>
</head> 
<body> 
<p>这里没用<p>This is probably the most common mishap. The remedy is simple--yank! It's most easily done
	with two people. One to restrain the bird and the <a href="#"> This is a link. Hover me 
	toThis is a link. Hover me toThis is a link. Hover me toThis is a link. Hover me to
	highlight the parent paragraph.</a> other to pull the feather. Use pliers, or a hemostat. Tweezers won't
	work on primaries. Make certain that the wing bones are firmly supported or you can break the wing.
	Clamp onto the feather and give a sharp tug in the direction of the feather. The feather will come
	out. Next, apply gentle, direct pressure to the follicle where the feather was to stop the bleeding.
	Dab some styptic powder on it, as it will help stop the bleeding as well. Let the bird rest. Ask
	your vet or breeder to demonstrate exactly how to pull a blood feather if you're apprehensive about
	doing it.</p></p>

	
	<p>This is probably the most common mishap. The remedy is simple--yank! It's most easily done
	with two people. One to restrain the bird and the <a href="#"> This is a link. Hover me to
	highlight the parent paragraph.</a> other to pull the feather. Use pliers, or a hemostat. Tweezers won't
	work on primaries. Make certain that the wing bones are firmly supported or you can break the wing.
	Clamp onto the feather and give a sharp tug in the direction of the feather. The feather will come
	out. Next, apply gentle, direct pressure to the follicle where the feather was to stop the bleeding.
	Dab some styptic powder on it, as it will help stop the bleeding as well. Let the bird rest. Ask
	your vet or breeder to demonstrate exactly how to pull a blood feather if you're apprehensive about
	doing it.</p>

<!--hover(over, out)
一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法。这是一个自定义的方法,它为频繁使用的任务提供了一种“保持在其中”的状态。 当鼠标移动到一个匹配的元素上面时,会触发指定的第一个函数。
当鼠标移出这个元素时,会触发指定的第二个函数。而且,会伴随着对鼠标是否仍然处在特定元素中的检测(例如,处在div中的图像),如果是,则会继续保持“悬停”状态,而不触发移出事件(修正了使用mouseout事件的一个常见错误)。
over (Function): 鼠标移到元素上要触发的函数 
out (Function): 鼠标移出元素要触发的函数 
示例
jQuery 代码:
$("p").hover(function(){ $(this).addClass("over"); },function(){ $(this).addClass("out"); });


parents( String expr )
取得一个包含着所有匹配元素的唯一祖先元素的元素集合(不包含根元素)。
-->

</body> 
</html> 

2


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

静山晚风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值