zoukankan      html  css  js  c++  java
  • Jquery(2)

    1, 隐式迭代,当没有找到控件时,可以按照以下方式处理

    $(function () {
                var elements = $("#txt1");
                if (elements.length <= 0) {
                    alert("没有找到文本框");
                }
                elements.mouseover(function () {
                    alert("移动上来了");
                });
            });

    2,next()获取同辈相邻的下一个元素

    $(function () {
                $("p").click(function () {
                    alert($(this).next().text());
                });
            });

    3,nextall() 获取同辈下面的所有元素

    $(function () {
                $("p").click(function () {
                    alert($(this).nextAll().text());
                });
            });

    4,nextall() 也可以作为数组使用

     $(function () {
                $("p").click(function () {
                    $.each($(this).nextAll("p"), function () {  //添加P元素过滤器
                        $(this).css("background", "red");
                    });
                });
            });

    5,siblings() 获取所有同辈对象

    $(function () {
                $("p").click(function () {
                    $(this).css("background", "blue");
                    $(this).siblings("p").css("background", "red");
                });
            });

    6,链式编程写法

    例子1,$(function(){

      $("p").click(function(){

        $("p").click(function(){

          $(this).css("background","blue").siblings("p").css("background","red");

        });

      });

    });

    例子2,$(function(){

      $("#table1 td").Html("<image url="~/nostar.jpg" />") //table 下的td元素,如果用#table > td 代表table相邻子集的td元素

      .mouseover(function(){});

        $("#table1 td").Html("<image url="~/fillstar.jpg" />").nextall().Html("<image url="~/nostar.jpg" />");

      });

    });

  • 相关阅读:
    Leetcode 191.位1的个数 By Python
    反向传播的推导
    Leetcode 268.缺失数字 By Python
    Leetcode 326.3的幂 By Python
    Leetcode 28.实现strStr() By Python
    Leetcode 7.反转整数 By Python
    Leetcode 125.验证回文串 By Python
    Leetcode 1.两数之和 By Python
    Hdoj 1008.Elevator 题解
    TZOJ 车辆拥挤相互往里走
  • 原文地址:https://www.cnblogs.com/guoyinghai/p/Jquery2.html
Copyright © 2011-2022 走看看