- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 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"]
+"'> "
+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/
大家好,感谢您抽出时间, 我最近一直在摆弄 jQuery(简而言之,我是一个新手),我对“parents()”方法很感兴趣。在 jquery.com 上的文章中,他们展示了一个示例,该示例允许显示
完全是使用 jQuery 的新手,但遇到了一些问题。 我有一个表格,其中一些单元格中有一个(每个单元格不得超过一个选择)。 在以下代码中,select 是传递给函数的元素。我正在尝试获取父级,以便我可
我有一个 anchor ,并且已经附加了一个 onClick 回调,因此一旦单击它,就会触发一个 AJAX 请求,该请求会调用一个从数据库中删除图像的 View 。它还应该删除 完全一样,但是由于某种
我在使用 jQuery 获取元素的父元素列表时遇到一些问题。 也许我遗漏了一些东西,但我在几个嵌套的 div 中有一个链接,并且正在尝试获取 parent 的 parent 的 sibling 列表。
我在 jQuery 中为每个循环使用以下选择器: $("#myid").parents().andSelf().each(function({}) 选择器返回一个像这样的对象: object[html
我试图通过单击按钮获取表格单元格内两个输入字段(一个文本字段和一个选择字段)的值。 Seconds Minutes Hours
我是一名优秀的程序员,十分优秀!