2011-08-10 10 views
0
var standard_anchor = new Array(); 
    standard_anchor[0] = "http://1-9-9-1.tumblr.com/"; 
    standard_anchor[1] = "http://www.egs.edu/faculty/jean-baudrillard/articles/simulacra-and-simulations-viii-the-implosion-of-meaning-in-the-media/"; 
    standard_anchor[2] ="http://www.bopsecrets.org/images/sos.pdf"; 
    standard_anchor[3] ="http://rads.stackoverflow.com/amzn/click/2915173729"; 
    standard_anchor[4] ="http://www.gagosian.com/exhibitions/2011-06-27_takashi-murakami/"; 
    standard_anchor[5] ="http://www.chloepiene.com/work.html"; 
    standard_anchor[6] ="#"; 
    standard_anchor[7] ="http://en.wikipedia.org/wiki/Takashi_Murakami#Market_Value"; 
    standard_anchor[8] ="http://www.imdb.com/title/tt0094625/"; 
    standard_anchor[9] ="http://en.wikipedia.org/wiki/Icarus"; 
    standard_anchor[10] ="http://gundam.wikia.com/wiki/Heero_Yuy"; 
    standard_anchor[11] ="http://rads.stackoverflow.com/amzn/click/B000KF0P2I"; 
    standard_anchor[12] ="http://gundam.wikia.com/wiki/Char_Aznable"; 
    standard_anchor[13] ="http://gundam.wikia.com/wiki/Zeta_Gundam"; 
    standard_anchor[14] ="http://en.wikipedia.org/wiki/Genocide"; 
    standard_anchor[15] ="http://www.guardian.co.uk/uk/2011/aug/09/mark-duggan-police-ipcc"; 
    standard_anchor[16] ="http://en.wikipedia.org/wiki/Race_and_the_War_on_Drugs"; 
    standard_anchor[17] ="http://www.imdb.com/title/tt0259484/"; 

    var standard = function(){ $.each(standard_anchor,function(value){ return value }); }; 



$(document).ready(function(){ 


    //lazy load 
    $(function(lazyload){ 

    $("#content img").lazyload({ threshold : 5, effect : "fadeIn" }); 

    }); 

    //anchor handler 


     /* should replace all a href values with reversed iterated standard anchor data */ 
      $('a [href]').reverse().each(function(i){$(this).attr('href', standard_anchor[i])}); 






//end 
}); 

これは正しくフォーマットされていないと記録に残っています。すべてのhrefの値を配列の値に変更する

これは私のhtmlのhref値にこれらの配列の値を取り込むことを望んでいましたが、これはうまくいきませんでしたが、私はこれの細かい点は不明ですが、アンカータグを逆にたどる関数に配列の値を返す変数が、これを達成する最も効率的な手段になります。私はこれに似た質問をし、私の標準変数を現在の状態に再フォーマットすることを勧告されました(明らかに理由のないようにjQueryメソッドで入れ子にしました)。アンカータグを選択して横断した文を再フォーマットする)私は今これがうまくいかない理由が何であれ謙虚に尋ねますか?

+1

あなたは 'a'と' [href] 'のギャップを埋もうとしましたか?それはスペースであるため、 'a'の子孫である' href'属性を持つ要素の選択を意味します。代わりに '$( 'a [href]')'を使ってみてください。 –

+0

おかげさまで私はそれをやったことさえ知りませんでした。 –

+0

トーマスさんは本当にありがとうございます。 –

答えて

2

問題は、単に間違った選択である:$('a [href]')を、$('a[href]')でなければなりません。

前者が後者を選択する一方、href属性を持つすべてa要素をa要素の子孫だhref属性を持つ要素を選択します。

0

私はiの値が正しくないと賭けました。

試してみてください。

var i = $('a [href]').length 
$('a [href]').reverse().each(function(){$(this).attr('href', standard_anchor[i--])}); 
0

私はあなたのセレクタがここにちょうど間違っているかなり確信しています。代わりにこれを試してみてください:

$('a').reverse().each(function(i){$(this).attr('href', standard_anchor[i])}); 
関連する問題