jQuery 常用方法1(持续更新)
1.hide():隐藏
eg)
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
2.show ( ) :显示
eg)
$("#show").click(function(){
$("p").show();
});
3.parent ()和parents ( ):前一个寻找当前元素的父元素,后一个寻找当前元素的所有祖先元素(不包含根元素)
eg)
http://www.cnblogs.com/myjavawork/articles/1868991.html
4.next ( ) 和 nextAll ()【参考:http://www.jb51.net/article/57233.htm】
next ( )方法:是指获得匹配元素的相邻同同辈元素(即下一个同辈元素),注意,同辈元素并不是标签相同的元素,而是指该元素闭合后的下一个元素,如下例中的”<div>美女,亲一下</div>“,div闭合后的下一个元素为<p>。则$("div").next()就是<p>。
<div>美女,亲一下</div> <p>我是p标签</p>
nextAll()方法:指获得匹配元素之后所有的同辈元素。
eg)
<html>
<head>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//$("div").click(function(){alert($(this).next().text());});
//$("div").click(function(){alert($(this).nextAll().text());});
$("div").click(function(){alert($(this).nextAll("div").text());});
});
</script>
<style type="text/css">
div{width:300px;height:30px;background:green;margin-top:10px;}
</style>
</head>
<body>
<div id="uu">您好,<font color="blue">美女</font></div>
<div>hello,world</div>
<div>美女,亲一下</div>
<p>我是p标签</p>
<div><span>我很帅,有图有真相</span></div>
<p>我也是p标签</p>
</body>
</html>
这里,和上面链接的作者一样提出一个疑问:
$("div").click(function(){alert($(this).nextAll("div").html());});
它并不能获取接下来所有的“同辈”的html,而只是获得下一个同辈元素的html内容。为什么??
持续更新ing。。。

浙公网安备 33010602011771号