获取HTML部分中每个链接的href属性 [英] Get the href attribute for each link in a section of HTML

查看:84
本文介绍了获取HTML部分中每个链接的href属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下jQuery,以遍历HTML部分中的每个<a>对象:

I've written the following jQuery to loop through each of the <a> objects in a section of HTML:

$(".chapterindex" + key + " div.link a").each(function(intIndex){
  alert("Numbered index: " + intIndex);
});
});

jQuery第一行中使用的键值来自我手动构建的URL数组,如下所示:

The key value used in the first line of the jQuery is from an array of URL's I've built manually, something like this:

var chapters = new Array();
chapters[0] = "original/html/0/ID0EFJAE.html";

我可以提醒intIndex,这会给我0,1,2,3,4,5....等.

I can alert the intIndex which gives me, 0,1,2,3,4,5.... etc..

但是如何扩展上面的jQuery,以从HTML中找到的每个链接中获取href属性?

But how can I extend the jQuery above to get the href attribute from each of the links found in the HTML?

推荐答案

尝试一下:

$(".chapterindex" + key + " div.link a").each(

    function(intIndex){
        alert( "Numbered index: " + intIndex );

        var href = $(this).attr('href');
    });
});

这篇关于获取HTML部分中每个链接的href属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆