我有一段有人为我写的代码,如下所示:
var $me = $('.me'),
crazyNumber = 99999999,
allOfYou = [
{
elements: $me.parentsUntil('.you'),
target: $me.parentsUntil('.you').parent()
},
{
elements: $me.nextUntil('.you'),
target: $me.nextUntil('.you').andSelf().filter(':last').next()
},
{
elements: $me.prevUntil('.you'),
target: $me.prevUntil('.you').andSelf().filter(':last').prev()
}
],
sorted = allOfYou.sort(function (objA, objB) {
var a = objA.elements.length + 1 || crazyNumber,
b = objB.elements.length + 1 || crazyNumber;
return a - b;
});
$('#who').html('you ' + sorted[0].target.data('verb') + ' me');
最后,我想div#who
从我那里得到 html,但我不明白代码,我试过了:target.data('verb')
$('#who').html(sorted[0].target.data.class);
$('#who').html(sorted[0].attr('class'));
$('#who').html(sorted[0] + $(this).attr('class'));
还有许多其他事情,似乎没有任何效果(我不熟悉 Jquery 目标..)