简明现代魔法 -> JQuery -> JQuery 学习:选取父节点

JQuery 学习:选取父节点

2010-05-06

效果演示

你鼠标移到链接处,这里不会受影响。 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 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. 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.

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 This is a link. Hover me to highlight the parent paragraph. 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.

一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法。这是一个自定义的方法,它为频繁使用的任务提供了一种“保持在其中”的状态。 当鼠标移动到一个匹配的元素上面时,会触发指定的第一个函数。

当鼠标移出这个元素时,会触发指定的第二个函数。而且,会伴随着对鼠标是否仍然处在特定元素中的检测(例如,处在div中的图像),如果是,则会继续保持“悬停”状态,而不触发移出事件(修正了使用mouseout事件的一个常见错误)。

over (Function): 鼠标移到元素上要触发的函数,out (Function): 鼠标移出元素要触发的函数。

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

JQuery Code

$(document).ready(function() {
	$("a").hover(function() {
		$(this).parents("span").addClass("highlight");
	}, function() {
		$(this).parents("span").removeClass("highlight");
	});
});

CSS

.highlight { background:#ffe4b5; border: 1px dotted #eee; }

再来一个示例

下面的按钮在一个 td 标签内,点击它可以选取它的上一级标签(即 td)旁边的标签(隔壁的td)的内容(即“欢迎来到简明现代魔法”)。

欢迎来到简明现代魔法!

JQuery Code

<script type="text/javascript"> 
$(document).ready(function() {
	$("#btn1").click(function(){
		alert($(this).parent().next().html());
			//this.parent()是input前面的td
			////this.parent().parent()获取的是tr
			//////this.parent().parent().parent()获取的是table
			////////this.parent().next()获取的是td相临的td
});
});
</script> 
  
<table>
<tr>
      <td><input id="btn1"  class="btn" type="button"  value="click me"/></td>
      <td>欢迎来到简明现代魔法!</td>
</tr>
</table>
随机文章推荐
网站分类


注:如需转载本文,请注明出处(原文链接),谢谢。更多精彩内容,请进入简明现代魔法首页。

进入新博客
喜欢本文,就分享它吧
给我留言
您的名字:
您的邮件:
您的网站:


 

copyright © 2009 简明现代魔法    学习、分享、进步

power by Gonn 感谢所有关心和支持本站的朋友们