一、next
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<form>
<input id="test" />
<input id="test1"/>
<input id="test2" />
</form>
<form>
<input />
<input />
<input />
</form>
<script>
console.log($("#test").next()[0]);
//获取id="test"同辈中的下一个
</script>
</body>
</html>
二、nextAll
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<form>
<input id="test" />
<input id="test1"/>
<input id="test2" />
</form>
<form>
<input />
<input />
<input />
</form>
<script>
$("#test").nextAll().each(function(){
console.log(this);
});
//获取id="test"之后的所有同辈
</script>
</body>
</html>
添加选择器:
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<form>
<input id="test" />
<input id="test1"/>
<input id="test2" />
</form>
<form>
<input />
<input />
<input />
</form>
<script>
$("#test").nextAll("#test2").each(function(){
console.log(this);
});
//获取id="test"之后的所有同辈,并根据("#test2")进行筛选
</script>
</body>
</html>