Jquery通过指定层次关系获取元素

html代码

<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:

<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>

 

 

转载于:https://www.cnblogs.com/abenmao/archive/2012/02/28/2371878.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值