$('#content h2').each(function(index) { //选择所有id号为content下的h2标签,获取的是content中h2的index?
    var chapterTitle = $(this);
    var chapterId = 'chapter-' + (index + 1);
    chapterTitle.attr('id', chapterId);
    $('<a></a>').text(chapterTitle.text())
      .attr({
        'title': 'Jump to ' + chapterTitle.text(),
        'href': '#' + chapterId
      })
      .appendTo('#page-contents div');
  });