zoukankan      html  css  js  c++  java
  • Jquery 对象集合的迭代扩展forEach

     1 if (jQuery && !jQuery.fn.forEach) {
     2     $(function () {
     3         (function ($) {
     4             $.fn.extend({
     5                 forEach: function (predicate) {
     6 
     7                     if (this == null) {
     8                         throw new TypeError(' this is null or not defined');
     9                     }
    10 
    11                     // 1. Let O be the result of calling toObject() passing the
    12                     // |this| value as the argument.
    13                     var O = Object(this);
    14 
    15                     // 2. If isCallable(predicate) is false, throw a TypeError exception. 
    16                     if (typeof predicate !== "function") {
    17                         throw new TypeError(predicate + ' is not a function');
    18                     }
    19 
    20                     //3 call the jq  original API  for iteror
    21                     $.each(O, function (index, domEle) {
    22                         predicate($(domEle));
    23                     });
    24                 }
    25             })
    26         })(jQuery);
    27 
    28     });
    29 }
  • 相关阅读:
    (水题)洛谷
    (水题)洛谷
    洛谷
    (水题)洛谷
    POJ
    poj 3061(二分 or 尺取法)
    poj 2456(二分)
    poj 1064(二分答案)
    POJ 2559(单调栈)
    STL
  • 原文地址:https://www.cnblogs.com/micro-chen/p/5873316.html
Copyright © 2011-2022 走看看