gpt4 book ai didi

jQuery 使用 .html() 但需要排除一个元素

转载 作者:行者123 更新时间:2023-12-01 05:53:58 25 4
gpt4 key购买 nike

我正在使用.html()拉出 <li> 的列表来自div但我需要排除 liid#donate-link

目前我的 jQuery 是

var _topbarmenu = $("<div/>").attr({
"id": "topbarmenu",
}).append($('.tabs').html())
.prepend("<li id='shop-link'>"+_pm+"</li>");

如您所见,我正在使用 $('.tabs').html() 提取数据我已经尝试过$('.tabs').html().not('#donate-link')但这似乎不起作用。

编辑额外内容

var _topbarmenucontent = $('#header .tabs').html();
$(_topbarmenucontent).find('#donate-link').remove();
var _topbarmenu = $("<div/>").attr({
"id": "topbarmenu",
}) .append(_topbarmenucontent)
.prepend("<li id='shop-link'>"+_pm+"</li>");
var _topcontent = $("<div/>").append(_topbarlogo).append(_topbarmenu);
$(_topbar).append(_topcontent);

$("#wrap").prepend(_topbar);
$(window).scroll(function(e){
if ($(window).scrollTop() > 170) {
console.log('>10');
$(_topbar).slideDown();
} else if ($(window).scrollTop() == 0) {
console.log('0');
$(_topbar).slideUp();
} else {
console.log('0');
$(_topbar).slideUp();
}
});

HTML

    <ul class="tabs">
<li id="shop-link" class="garage-link"><a href="/board" class="mainmenu" original-title="Visit the Board"><span>Board</span></a></li>
<li id="shop-link" class="garage-link"><a href="./garage.php" class="mainmenu" original-title="Visit the Virtual Garage"><span>Garage <i>[BETA]</i></span></a></li>
<li id="shop-link" class="upload-an-image"><a href="#" original-title="Upload an Image"><span>Upload Image</span></a></li>
<li id="shop-link"><a href="/board/merch" original-title="Purchase items from Enthst Store"><span>Store</span></a></li>
<li id="members-link"><a href="./memberlist.php" original-title="View complete list of members"><span>Members</span></a></li>
<li id="donate-link"> <a href="#" target="_blank" original-title="Donate"><span>Donate</span></a></li>
</ul>

添加编辑 JSFIDDLE

JSFIDDLE

最佳答案

这应该有效:

$('.tabs').not('#donate-link').html()

您的代码不起作用,因为 html 返回一个字符串,而不是可以链接的 jQuery 对象。

祝你好运

关于jQuery 使用 .html() 但需要排除一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18102215/

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