我编写了以下 jQuery 来遍历每个 <a>
HTML 部分中的对象:
$(".chapterindex" + key + " div.link a").each(function(intIndex){
alert("Numbered index: " + intIndex);
});
});
jQuery 第一行中使用的键值来 self 手动构建的 URL 数组,如下所示:
var chapters = new Array();
chapters[0] = "original/html/0/ID0EFJAE.html";
我可以提醒 intIndex
这给了我,0,1,2,3,4,5....
等..
但是我如何扩展上面的 jQuery 以获得 href
HTML 中每个链接的属性?
最佳答案
试试这个:
$(".chapterindex" + key + " div.link a").each(
function(intIndex){
alert( "Numbered index: " + intIndex );
var href = $(this).attr('href');
});
});
关于javascript - 获取一段 HTML 中每个链接的 href 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7759823/