开发者

changing all href values to array values theory and practice

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://www.amazon.com/Murakami-Versailles-Laurent-Bon/dp/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.wi开发者_如何转开发kipedia.org/wiki/Icarus";
    standard_anchor[10] ="http://gundam.wikia.com/wiki/Heero_Yuy";
    standard_anchor[11] ="http://www.amazon.com/Mobile-Suit-Gundam-Chars-Counterattack/dp/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
});

for the record if this is formatted improperly I've been teaching my self all this with no help until last night from anyone.

I hoped that this would work to populate all of the href values in my html with these array values however this doesn't work, I'm unclear on the finer points of alot of this but on my own I that that a variable that returned the array values to a function that reverse traversed my anchor tags would be the most efficient means to accomplish this. I asked a similiar question to this and was advised to reformat my standard variable to it's current state(i nested it in a jQuery method for no reason apparently) as well as to reformat the statement that selected and traversed the anchor tags(which I did) I now humbly ask what is the reason that this doesn't work?


The problem is simply the incorrect selector: $('a [href]'), should be $('a[href]').

The former selects an element with an href attribute that's a descendent of an a element, whereas the latter selects all a elements with the href attribute.


I bet the value of i is not correct.

Try:

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


I'm pretty sure your selector is just wrong here. Try this instead:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜