gpt4 book ai didi

javascript - jQueryparents() 和parent().parent() 只能看到上一级?

转载 作者:行者123 更新时间:2023-12-02 20:48:11 25 4
gpt4 key购买 nike

我在使用 jQuery 获取元素的父元素列表时遇到一些问题。

也许我遗漏了一些东西,但我在几个嵌套的 div 中有一个链接,并且正在尝试获取 parent 的 parent 的 sibling 列表。

不过,我似乎只能从链接上一级,所以我不能

HTML 如下:

<div class="alertcontainer">
<div id="alertnode_1" class="alertnode">
<div class="alertnodeheader">Escalate to Level 1</div>
<div class="alertnodebody">
<div class="bold">Alert these people:</div><br/>
<div class="alertnodebodycontactlist">
<div class="alertnodebodycontact">187
<a id="d0.9659762698410487"
onclick="RemoveNode(this, 187)"
href="#">Remove Me...</a>
</div>
<div class="alertnodebodycontact">185
<a id="d0.6609632486132389"
onclick="RemoveNode(this, 185)"
href="#">Remove Me...</a>
</div>
<div class="alertnodebodycontact">184
<a id="d0.13180038199138278"
onclick="RemoveNode(this, 184)"
href="#">Remove Me...</a>
</div>
<div class="alertnodebodycontact">186
<a id="d0.6364304467227213"
onclick="RemoveNode(this, 186)"
href="#">Remove Me...</a>
</div>
<select class="esccontactlist" id="esc_contact_list_1">
<option>Also alert...</option>
</select>
</div>
<br/>
</div>
</div>
</div>

JS/jQuery如下:

function RemoveNode(e, id)
{
// Remove the contact
$(e).parents().filter('.alertnodebodycontact').remove();

// Add it back into the list.
for ( var i = 0; i < ContactList.length; i++)
{
if ( id == ContactList[i]["ContactID"] )
{
$('#esc_contact_list_1')
.append("<option value='"
+ContactList[i]["ContactID"]
+"'>&nbsp;&nbsp;"
+ContactList[i]["ContactName"]
+" ("
+ContactList[i]["PrimaryEmail"]
+")</option>");
}

// Here, I want to count the number of '.alertnodebodycontact' divs.
// However, $(e).parents() only returns a single item, which is the
// '.alertnodebodycontact' that the link is in.
// Likewise, $(e).parent().parent() returns nothing.

// Anyone have any idea why the outer divs aren't being returned?

}
}

最佳答案

没关系...我正在尝试删除它后访问它。只需要重新排序我的任务即可。

关于javascript - jQueryparents() 和parent().parent() 只能看到上一级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/563375/

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