- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码,它没有发出任何警报,也没有返回任何好的 :(第一部分工作正常但事后它没有:(我似乎无法弄清楚问题是什么..
this.getNextItem = function(o) {
// given <li> playlist item, find next <li> and then <a>
if (o.nextElementSibling) {
o = o.nextElementSibling;
}
else {
o = o.nextSibling;
}
while (o && o.className !== 'playerr') {
if (o.nextElementSibling) {
o = o.nextElementSibling;
} else {
o = o.nextSibling;
}
}
if(o){ if (o.className !== 'playerr') { //nodeName.toLowerCase()
return null;
} else {
alert(o.className);
alert(o.getElementsByTagName('a')[0]);
return o.getElementsByTagName('a')[0];
}}
};
如果您想查看完整的上下文,请使用 http://beastdrops.com然后在 consol 中运行 page("content2") 以获取新的“播放器”将歌曲转发到结尾,然后当它要切换到下一首时,它不会... :( 这就是这个脚本必须做的
最佳答案
好的,根据您的意见,您似乎想做 nextByClass()
所以这是一个版本:
function hasClass(elem, cls) {
var str = " " + elem.className + " ";
var testCls = " " + cls + " ";
return(str.indexOf(testCls) != -1) ;
}
function nextByClass(node, cls) {
while (node = node.nextSibling) {
if (hasClass(node, cls)) {
return node;
}
}
return null;
}
工作演示:http://jsfiddle.net/jfriend00/3L9FL/
您可以使用它来查找具有所需类别的同一级别的下一个项目,如下所示:
// assumes you pass it the node for the starting <li>
// returns first link in next <li> with the desired classor null if none
this.getNextItem = function(node) {
node = nextByClass(node, "playerr");
if (node) {
return node.getElementsByTagName('a')[0];
}
return null;
}
旧版本的答案被评论中的澄清所取代:
根据代码中的注释,给定的元素似乎是 <li>
标签,你只想找到下一个<li>
在同一水平上。如果是这样的话,这里有一个非常简单的函数,它可以找到同一个 tagName 的下一个兄弟:
// gets the next sibling with the same tagName as the starting point
// returns null if none found
function nextByTag(node) {
var tag = node.tagName;
while (node = node.nextSibling) {
if (node.tagName === tag) {
return node;
}
}
return null;
}
您可以使用它来查找下一个 <li>
中的第一个后代链接像这样:
// assumes you pass it the node for the starting <li>
// returns first link in next <li> or null if none
this.getNextItem = function(node) {
node = nextByTag(node);
if (node) {
return node.getElementsByTagName('a')[0];
}
return null;
}
关于javascript - NextSibling 类不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23963208/
我们能够运行此代码 str.parentNode.nextSibling.tagName 并获得相应的名称。我们需要的是 nextSibling 之后的 nextSibling 所以我们尝试了这个 s
销毁自己的示波器时,我在程序中始终遇到此错误。我在角度范围内跟踪到了这个while循环: if (!(next = (current.$$childHead || (current !== targe
我目前正在做一个项目,我必须填充表格的不同列,因为我正在使用 .nextSibling,但是如果我定位,行可能会很长,让我们说第 4 列: firstTd.nextSibling.nextSiblin
这是我的代码,它没有发出任何警报,也没有返回任何好的 :(第一部分工作正常但事后它没有:(我似乎无法弄清楚问题是什么.. this.getNextItem = function(o) { //
我想知道属性 NextSibling 如何在使用方法 getElementsByClassName() 的情况下有效?这是显示问题的代码示例: function Sibling() { var
我希望下面的代码能够提醒“out” this is output 但它会提示 undefined为什么? 最佳答案 nextSibling 选择元素的下一个兄弟节点。下一个节点也可以是 textNo
function function1() { var m = document.getElementById("myNodeOne").nextSibling; m.innerHTM
我正在尝试使用以下内容获取内容“我的家庭地址”,但得到了 AttributeError: address = soup.find(text="Address:") print address.next
OT/UT ENTRY
此 Meteor 客户端代码尝试获取 2 个值。 (1)this.label中的值的{{this.label}}线。 (2){{this.result}}中的值在线 当我单击 input 时,就会发生
我目前正在编写一个 Accordion 并遇到了与 nextSibling difference between IE and FF? 中描述的相同问题。 - Microsoft 的 nextSibl
我看到这两个属性的描述是只读的。那么这意味着什么,因为我做了一个使用 firstChild 像 的小测试 $('#one').firstChild.textContent = "ssss"。 最佳答案
我确信这个问题有一个简单的答案,但我无法构建一个搜索问题来将其找出来。 我有多个“nextSibling”属性来在一组未经修饰的 td 标签之间移动,总共需要 22 个。 有没有办法将这些相乘,例如'
我有一个包含单元格的表格,我可以在其中输入值(该表格是一个时间表,我可以通过双击该单元格在单元格中输入房间号)。现在我想在 tab 键上添加一个键监听器。如果我按下 tab 键,当前单元格中的值应该被
当我调用 querySelectorAll('#fchildP') 并且想要获取它的firstChild 节点时,它返回数据属性为 的 #text node\n resp "breakline" 和
我正在尝试附加到多个 div 的下一个元素。到目前为止我有这个: HTML 函数运行后,内容应如下所示: My content My content My content 这是我迄今
我有以下 span 元素: Type here please. Name here first name 使用下面的js函数,我可以获得之间的长度和 : $('span.insid
这不完全是代码中的问题,但我无法理解问题背后的原因。首先,请看一下代码: HTML: Head First : Javascript
我仍在尝试了解 NextSibling,并且我在 excel VBA 中使用 XMLHTTP。 这是元素的 HTML
我正在使用 HtmlAgilityPack 抓取一些数据。 HTML 看起来像这样: Field Name Value for above field name
我是一名优秀的程序员,十分优秀!