我有在.help
类中追加div(帮助图标)的所有元素的函数。从追加到元素的标题属性中获取文本
jQuery().ready(function() {
jQuery('.help').append('<div class="mark"></div>');
});
我需要什么要补充的功能得到.help
元素的标题属性信息?
我是新来的脚本。
我有在.help
类中追加div(帮助图标)的所有元素的函数。从追加到元素的标题属性中获取文本
jQuery().ready(function() {
jQuery('.help').append('<div class="mark"></div>');
});
我需要什么要补充的功能得到.help
元素的标题属性信息?
我是新来的脚本。
利用的事实,append()
还可以接受,这将创建HTML字符串附加功能:
$('.help').append(function() {
return '<div class="mark" title="' + $(this).attr('title') + '"></div>';
});
+1使用函数参数 - 很好。 – johnhunter 2011-03-11 10:25:05
var title = $('.help').attr("title");
尝试使用attr功能:
jQuery().ready(function() {
console.log(jQuery('.help').attr('title'));
});
我想这是你想要什么:
});
是的@johnhunter,我很高兴发布我的(第一次)答案,只是为了看到其他人也在做同样的事情,在同一分钟:) – ctekse 2011-03-11 10:12:59
我认为您正在寻找这样的事情:
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
到每个帮助元素,并设置标志的标题是父的帮助标题。
@ctekse - 重新思考同一行:) – johnhunter 2011-03-11 10:09:40
伟大这是我正在寻找的':] – gidzior 2011-03-11 10:16:15
你需要获取或设置信息“标题”的每个元素的属性,以“帮助“班? – FarligOpptreden 2011-03-11 09:54:00
查看jQuery API文档(http://api.jquery.com/each/)中的'each'方法。 – Lazarus 2011-03-11 09:55:11
我真的不明白你的问题。你能告诉更多你的问题吗? – 2011-03-11 09:55:22