我有功能,附加div (帮助图标)后,所有元素与.help类。
jQuery().ready(function() {
jQuery('.help').append('<div class="mark"></div>');
});要从.help元素标题属性中获取信息,需要向该函数添加什么内容?
我是个脚本新手。
发布于 2011-03-11 18:21:44
利用append()还可以接受一个函数的事实,该函数将创建要追加的HTML:
$('.help').append(function () {
return '<div class="mark" title="' + $(this).attr('title') + '"></div>';
});发布于 2011-03-11 18:08:06
我想这就是你想要的:
jQuery().ready(function() {
jQuery('.help').each( function(index, elem){
$(this).append('<div class="mark" title="' + $(this).attr("title") + '"></div>')
});});
发布于 2011-03-11 18:08:34
我想你要找的东西是这样的:
jQuery().ready(function() {
// with each help element....
jQuery('.help').each(function () {
// create the empty mark, add the title from help, append mark to help
$('<div class="mark"></div>').attr('title', $(this).attr('title')).appendTo(this);
});
});这将为每个帮助元素添加一个div.mark,并将标记的标题设置为父帮助的标题。
https://stackoverflow.com/questions/5271377
复制相似问题