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>
    多思考,多创新,才是正道!
  • 相关阅读:
    PyQT5速成教程-4 Qt Designer实战[上]
    使用Qt Designer进行布局
    PyCharm+QT Designer整合
    Qt Designer 的使用
    Python | 一行命令生成动态二维码
    Python 标准库、第三方库
    Python list列表的常用操作方法
    Python+Selenium 自动化测试获取测试报告内容并发送邮件
    ”Tomcat version 5.5 only supports J2EE 1.2, 1.3, and 1.4 Web modules“解决方案
    linux查找符合条件的文件并删除
  • 原文地址:https://www.cnblogs.com/shuang121/p/2264176.html
Copyright © 2011-2022 走看看