问题描述
我的div具有完全相同的名称。
在页面加载时,我想从它们那里获取信息,例如$('.myclass').attr("title");
做,然后对他们做一些事情,并使其输出为div内容。
基本上像这样的 ,它 title属性并对其执行操作并输出结果。 即使它们都具有相同的类名,它们也被视为唯一。
1楼
专门为此jQuery提供的方法:
$('.myclass').each(function() {
var title = $(this).attr('title');
// do something with it
});
2楼
试试这个: :
循环遍历每个timeago
元素,获取title
并在格式化值旁边的div之前添加。
3楼
jQuery(document).ready(function() {
$("abbr.timeago").timeago();
$('.timeago').each(function() {
var strTitle = $(this).attr('title');
// do something with it
if(strTitle === "2010-01-17T01:59:17Z"){
$("#div1").html(strTitle);
}
});
});
请检查上面的JS小提琴