Learning jQuery, 4th Edition 勘误表

来源于:http://book.learningjquery.com/3145/errata/

 

Chapter 1

page 14

The CSS snippet is correct, but it differs from the CSS in the sample download at packtpub.com. Visit book.learningjquery.com for the complete updated code download.

Chapter 2

page 29

The first paragraph reads:

Notice that the first <ul> has an ID of selecting plays

It should read:

Notice that the first <ul> has an ID of selected plays

Listing 2.2

Line 3 of Listing 2.2 reads:

  $('#selected-plays li:not(.horizontal)').addClass('sub-
level');li:not(.horizontal)').addClass('sub-level');

It should read:

  $('#selected-plays li:not(.horizontal)').addClass('sub-level');

Listing 2.5

Lines 5–7 of Listing 2.5 read:

      .addClass('henrylink');
  });
});

Line 6 should be omitted, so the lines will just read:

      .addClass('henrylink');
});

page 46

The two code blocks incorrectely omit a space for the variable declaration. They begin:

varmyTag

They should begin:

var myTag

Chapter 3

no errata yet

Chapter 4

no errata yet

Chapter 5

no errata yet

Chapter 6

no errata yet

Chapter 7

no errata yet

Chapter 8

no errata yet

Chapter 9

Listing 9.8

The jQuery interface to the Sizzle selector engine changed in the late stages of the writing of this book, and the pseudo-selectors no longer receive the index of an element as one of their arguments. Instead, 0 is always passed as the variable, which causes our custom selector to break:


(function($) {
  $.extend($.expr[':'], {
    group: function(element, index, matches, set) {
      var num = parseInt(matches[3], 10);
      if (isNaN(num)) {
        return false;
      }
      return index % (num * 2) < num;
    }
  });
})(jQuery);

A replacement function can be written that uses Sizzle’s setFilters capability:


(function($) {
  $.expr.setFilters.group = function(elements, argument, not) {
    var resultElements = [];
    for (var i = 0; i < elements.length; i++) {
      var test = i % (argument * 2) < argument;
      if ((!not && test) || (not && !test)) {
        resultElements.push(elements[i]);
      }
    }
    return resultElements;
  };
})(jQuery);
More information on setFilters can be found here: https://github.com/jquery/sizzle/wiki/Sizzle-Documentation#wiki-sizzleselectorssetfilterslowercase_name--function-elements-argument-not--

Chapter 10

no errata yet

Chapter 11

no errata yet

posted @ 2016-12-09 16:59  一个勤奋的胖子  阅读(232)  评论(0编辑  收藏  举报