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.wikipedia.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
});
郑重声明,如果格式不正确,我一直在自学这一切,直到昨晚没有任何人的帮助。
我希望这能够用这些数组值填充我的 html 中的所有 href 值,但是这不起作用,我不清楚其中的很多细节,但就我自己而言,我认为将数组值返回到反向遍历我的 anchor 标记的函数的变量将是实现此目的的最有效方法。我对此提出了一个类似的问题,并建议将我的标准变量重新格式化为当前状态(显然我将其嵌套在 jQuery 方法中),并重新格式化选择并遍历 anchor 标记的语句(我这样做了) )我现在虚心请教这不起作用的原因是什么?
最佳答案
问题只是选择器不正确:$('a [href]')
,应该是$('a[href]')
。
前者选择具有 href
属性的元素,该属性是 a
元素的后代,而后者选择所有 a
元素使用 href
属性。
关于javascript - 将所有 href 值更改为数组值理论与实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7014462/