读书人

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

发布时间: 2012-08-29 08:40:14 作者: rapoo

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 提示

读书人网 >JavaScript

热点推荐