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" />");

      });

    });

  • 相关阅读:
    Iterable,Iterator和forEach
    集合的线程安全性
    Servlet生命周期
    JavaWeb应用的生命周期
    将博客搬至CSDN
    (五)新类库的构件
    Python input和print函数
    python----调试
    Excel决定吃什么
    MATLAB—地图
  • 原文地址:https://www.cnblogs.com/guoyinghai/p/Jquery2.html
Copyright © 2011-2022 走看看