gpt4 book ai didi

javascript - JQuery 从嵌套标签中抓取内容

转载 作者:行者123 更新时间:2023-12-03 08:53:21 24 4
gpt4 key购买 nike

我确信这个问题必须在某个地方得到回答,但是好吧。

我获得了需要从 HTML 页面获取的嵌套数据。想象一下嵌套<ul> , <li> , <div>等等。

我需要将它们转换为 JSON,因此我将首先在分层 Javascript 对象中构建数据。

由于它们是嵌套的,我想选择最大的组,并从那里构建。

在我选择最大的组之后,有没有办法进一步使用 JQuery 选择器从这个更大的组中选择标签?

$('.someclass').each(function(i) {
$(this); // what to do with this? so I select further nested data?
});

最佳答案

这是您要找的吗?

$('#myUl li').each(function(index, item) { // you can name the item here or use "this"

var $li = $(this);
// an alternative way is to do:
var $li = $(item);

// you can select items inside the li item, for example select an anchor
var $a = $li.find("a");
$a.attr("href","#home");
});

关于javascript - JQuery 从嵌套标签中抓取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32604722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com