总有人间一两风,填我十万八千梦

jQuery .Next Adjacent Selector ("prev + next") 用法 手册 | 示例代码

jQuery开发手册 归档 296℃ 0评论

Description: Selects all next elements matching "next" that are immediately preceded by a sibling "prev".

  • version added: 1.0jQuery( "prev + next" )

    prev: Any valid selector.

    next: A selector to match the element that is next to the first selector.

One important point to consider with both the next adjacent sibling selector (prev + next) and the general sibling selector (prev ~ siblings) is that the elements on either side of the combinator must share the same parent.

Example:

Finds all inputs that are next to a label.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>next adjacent demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form>
<label for="name">Name:</label>
<input name="name" id="name">
<fieldset>
<label for="newsletter">Newsletter:</label>
<input name="newsletter" id="newsletter">
</fieldset>
</form>
<input name="none">
<script>
$( "label + input" ).css( "color", "blue" ).val( "Labeled!" );
</script>
</body>
</html>

转载请注明:悠然品鉴 » jQuery .Next Adjacent Selector ("prev + next") 用法 手册 | 示例代码

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址