作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的文档中有 2 个 ul 元素。如何使用 PrototypeJS 找到 2 个中的第一个?我试过这段代码:
first = $$('ul[class="level0"]')[0];
second = $$('ul[class="level0"]')[1];
只有第一个是填充的,第二个是空的。有任何想法吗?这是我的 html:
<ul id="nav">
<li class="level0 nav-1 first level-top parent">
<ul class="level0">...</ul>
</li>
<li class="level0 nav-2 last level-top parent">
<ul class="level0">...</ul>
</li>
</ul>
谢谢:)
最佳答案
不要使用属性 CSS 选择器,而是使用类 CSS 选择器
first = $$('ul.level0')[0];
second = $$('ul.level0')[1];
但除此之外应该可行
还有其他方法 $$()
返回一个元素数组(即使是一个),你可以引用 .first()
first = $$('ul.level0').first()
请让我们知道修复 HTML 是否有效,或者如果您在 javascript 控制台中遇到任何错误 - 这可能会导致您遇到不同的问题
关于css - 原型(prototype) : How do I find the first element with a certain class?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13648350/
我是一名优秀的程序员,十分优秀!