.each()
を使用して、jQueryオブジェクト$firstParagraph
のリンクを反復処理しています。リンクを繰り返していくうちに、呼び出すたびに新しいオブジェクトを作成する$(this)
を呼び出すことなく、絶対の方法でそれらを参照したいと思います。リンク上でリンクを独立して2回反復すると(下のコードを参照)、両方のインスタンスで行われた作業が結合されないためです。これは物事が二つのループの間で変更することができますように良いアイデアがあれば
var elemArray = [];
// Iterate over the links once
$firstParagraph.find("a").each(function(i)
{
$this = $(this);
elemArray[i] = $this;
// Modify $this
});
// Iterate over the links a second time
$firstParagraph.find("a").each(function(i)
{
$this = elemArray[i];
// I want to modify $this again, but without loosing
// the work I did in the first iteration
});
私はよく分からない:
$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
両方のロジックを1つのループで組み合わせるのはなぜですか? – ShankarSangoli