返回介绍

Descendant Selector ("ancestor descendant")

发布于 2017-09-11 14:04:04 字数 1350 浏览 1081 评论 0 收藏 0

所属分类:选择器 > 层级

descendant selector

描述: 选择给定的祖先元素的所有后代元素。

  • 添加的版本: 1.0jQuery( "ancestor descendant" )

    ancestor: 任何有效的选择器。

    descendant: 一个用来筛选后代元素的选择器。

一个元素的后代可能是该元素的一个孩子,孙子,曾孙等。

例子:

查找所有表单下的input后代元素。

<!DOCTYPE html>
<html>
<head>
  <style>
 
  body { font-size:14px; }
  form { border:2px green solid; padding:2px; margin:0;
         background:#efe; }
  div { color:red; }
  fieldset { margin:1px; padding:3px; }
  </style>
  <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
  <form>
    <div>Form is surrounded by the green outline</div>
    <label>Child:</label>
    <input name="name" />
 
    <fieldset>
      <label>Grandchild:</label>
      <input name="newsletter" />
    </fieldset>
 
  </form>
  Sibling to form: <input name="none" />
<script>$("form input").css("border", "2px dotted blue");</script>
 
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文