- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个 html 结构:
<body>
<a>
<b>
<c>
<d>
</d>
</c>
</b>
</a>
</body>
我使用 <d>
元素作为开始的第一个节点。
问题:
var s= $("d").parentsUntil("body").andSelf().map(function(){
return this.tagName;
}).get();
它应该从底部开始到顶部意味着 s
数组应该看起来像 d,c,b,a
.
但它显然看起来像:["A", "B", "C", "D"]
这是为什么呢?
最佳答案
.andSelf()
导致 jQuery 重新排序数组。
你可以试试:
var s= $("d").parentsUntil("body").map(function(){
return this.tagName;
}).get();
此代码的输出如下所示:["C", "B","A"]
。
关于javascript - jQuery 中的 parentsUntil() 使用相反的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15062670/
我基本上想这样做: $('#myelement').parentsUntil( ".myStopper" ).css("overflow","visible"); 但是当它遍历每个父元素时,我想检查每
给定 html:
我的问题最好用例子来解释: 这个有效: $(startContainer).parents().each(function(index, parentNode) { if (parentNod
我有这个 html 结构: 我使用 元素作为开始的第一个节点。 问题: var s= $("d")
我一直在尝试使用 jquery parentsUntil 方法来隐藏按钮,直到选中一个单选框,但我似乎无法让它工作。这可能是显而易见的事情,但它已经困扰了我几天了。任何人都可以看到我做错了什么。 (
我有一个包含多个级别的标准列表,我需要检查特定项目的根,直到 $(e.target).parents('ul').length === 1 是否可以为此使用 .parentsUntil()?或者我可以
我是一名优秀的程序员,十分优秀!