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++中的类模板详细讲述
    函数模板和模板函数
    vs2008 快捷键大全
    #宏定义##
    多工程项目设置
    conemu 配置
    itcast-svn
    itcast-spring-三大框架整合
    Spring通知方法错误
    动态代理
  • 原文地址:https://www.cnblogs.com/shuang121/p/2264176.html
Copyright © 2011-2022 走看看