jQuery中children方法、next方法与nextAll方法

因为三种方法之间存在着相似之处,因此将它们放在一起去比较
1、children获得匹配元素的所有子元素组成的集合
2、next方法,取得一个紧邻后面元素集合
3、nextAll方法,取得当前元素之后所有的同辈元素
请看以下实例:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="../js/jquery-3.3.1.js"></script>
	</head>
	<body>
		<table>
			<th>
				<td>序号</td>
				<td>姓名</td>
			</th>
			<tr>
				<td>1</td>
				<td>小明</td>
			</tr>
			<tr>
				<td>2</td>
				<td>李华</td>
			</tr>
		</table>
		<script>
			$("body").children().each(function(){
				console.log(this);
			});
		
			$("th").next().each(function(){
				console.log(this);
			});
			
			$("th").nextAll().each(function(){
				console.log(this);
			})
		</script>
	</body>
</html>

它运行后的效果为:
在这里插入图片描述
解析该程序:
children方法会得到< table>< /table> < script>< /script>
next方法会得到< th>后的第一个< td>< /td>
而nextAll会得到< th>后所有的< td>< /td>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值