jQuery遍历之next()、nextAll()方法使用实例
jquery遍历:next()和nextAll()方法。实例如下:
<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>
说明:
(1)next()方法:是指获得匹配元素的相邻同同辈元素(即下一个同辈元素),注意,同辈元素并不是标签相同的元素,而是指该元素闭合后的下一个元素,如实例中的”<div>美女,亲一下</div>“,div闭合后的下一个元素为<p>。
(2)如果next()加上参数,即next("div"),如果下一个相邻元素不是div,则为空,即一定是相邻的。
(3)nextAll()方法:指获得匹配元素之后所有的同辈元素。它同样可以加上参数,nextAll("p")或nextAll("div")等等。
(4)有些奇怪的是,如果是这样的代码:
$("div").click(function(){alert($(this).nextAll("div").html());});
它并不能获得所有的html内容,而只是获得下一个同辈元素的html内容。???疑惑
您可能感兴趣的文章:
- jQuery遍历之next()、nextAll()方法使用实例
- jQuery遍历之next()、nextAll()方法使用实例
- Jquery节点遍历next与nextAll方法使用示例
- Jquery节点遍历next与nextAll方法使用示例
- jquery使用each方法遍历json格式数据实例
- jquery使用each方法遍历json格式数据实例
- jQuery 遍历 - 同层方法siblings() next() nextAll() nextUntil() prev() prevAll() prevUntil()(二十四)
- jQuery 遍历 - next() 方法
- jQuery基础教程之遍历节点siblings()方法使用说明
- 【js与jquery】jquery的一个通用的专门用于遍历的全局方法$.each()的使用
- Jquery AutoComplete的使用方法实例
- jQuery中使用data()方法读取HTML5自定义属性data-*实例
- jQuery遍历节点-find()方法使用说明
- Jquery AutoComplete的使用方法实例
- Jquery AutoComplete的使用方法实例
- jQuery中使用data()方法读取HTML5自定义属性data-*实例
- jQuery基础教程之DOM操作-遍历节点-next()方法
- js模仿jquery里的几个方法next, pre, nextAll, preAll
- jQuery 遍历-nextUntil()方法以及prevUntil()方法的使用介绍
- dom对象与jQuery对象的区别(使用实例方法)