首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jquery代码解释内中的title,jump to等

2012-08-29 
jquery代码解释其中的title,jump to等$(#content h2).each(function(index) {//选择所有id号为content下

jquery代码解释其中的title,jump to等
$('#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');
  });

[解决办法]
大概就是 根据dom的text值 添加title 提示

热点排行