我使用.each()
来遍历jQuery对象$firstParagraph
中的链接。在遍历链接时,我想以绝对的方式引用它们,而不调用$(this)
,每次调用它时都会创建一个新对象。因为当我在链接上单独遍历两次(如下面的代码所示)时,两个实例中完成的工作并未结合。
$firstParagraph = $("p").eq(0);
// Iterate over the links once
$firstParagraph.find("a").each(function()
{
$this = $(this);
// Modify $this
});
// Iterate over the links a second time
$firstParagraph.find("a").each(function()
{
$this = $(this);
// I want to modify $this again, but without loosing
// the work I did in the first iteration
});
你不应该修改'$(this)'。你想做什么? – SLaks
你在修改什么? – Sparkup
为什么不把两个逻辑结合在一个循环中? – ShankarSangoli