zoukankan      html  css  js  c++  java
  • Jquery通过指定层次关系获取元素

    html代码

    View Code
    <body>
        <form id="form1" runat="server">
        <span>dfdfdf</span>
         <label>子节点</label><input type="text" value="背景变成红色"/>
         <fieldset>
             <label>孙节点</label><input type="text" value="背景变成红色" /><span>dfdfdf</span>
             <label>成孙节点</label><input type="text" value="背景变成红色" />
             <input type="text" value="背景变成红色" /><span>dfdfdf</span>
         </fieldset>
        </form>
         <label>form外</label><input type="text" value="背景变成红色" />
        <fieldset>
            <label>form外</label><input type="text" value="背景变成红色" />
             <input type="text" value="背景变成红色" />
        </fieldset>
       <input type="text" value="背景变成红色" />
    </body>

    Jquery:

    View Code
      <script src="js/jquery-1.6.min.js" type="text/javascript"></script>
        <script type="text/javascript">
           jQuery(function($){
          // $("form input").css("backgroundColor","red");//获得form下面的所有input标签,祖先与父子的关系
          // $("form>fieldset>input").css("color","red"); //获得form下面fieldset下面的所有input标签,父子关系
         //  $("form>fieldset>input").css("backgroundColor","red");
         // $("label+input").css("backgroundColor","red");//获得所有label后面的input标签,label和input必须在一起,前后关系
         $("label~input~span").css("backgroundColor","red");//获得label后面的input后面的span标签
           })
        </script>
    多思考,多创新,才是正道!
  • 相关阅读:
    C#
    Excel 中大量图片如何快速导出? 转载自:http://www.zhihu.com/question/20800948
    IE的F12开发人员工具不显示 转载自:http://blog.csdn.net/longyulu/article/details/8749705
    firefox ie 比较 relative path
    fiddler save files
    selenium3加载浏览器
    Linux安装PHP
    客户端级别的渲染分析工具 dynaTrace
    前端性能分析:分析百度和sogou
    Linux vi的基本操作
  • 原文地址:https://www.cnblogs.com/shuang121/p/2264176.html
Copyright © 2011-2022 走看看