gpt4 book ai didi

javascript - Jquery each through 只给我 href

转载 作者:行者123 更新时间:2023-11-30 15:51:37 25 4
gpt4 key购买 nike

最佳答案

itemthis 代表一个 DOM 元素。当您将其视为字符串时,您将其转换为字符串。您可以使用 item.outerHTML - 您要查找的字符串 - 代替 item

     $.each( $('.nav-container>a'), function(i, item){
var menupunkt = '<li>' + item.outerHTML + '</li>'
console.log(i, menupunkt);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="nav-container desktop">
<a href="_index.php?page=_sub_papa&main=klassen">One</a>
<a href="_index.php?page=_sub_papa&main=tw">Twp</a>
</div>

注意

不确定它是否有优势,但我更愿意:

    $('.nav-container>a').each(function(i, item){
var menupunkt = '<li>' + item.outerHTML + '</li>'
console.log(i, menupunkt);
});

关于javascript - Jquery each through <a> 只给我 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39229604/

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