【发布时间】:2014-07-23 09:12:26
【问题描述】:
我正在尝试根据 <a> 标记中的特定 href 值在列表中显示特定项目。
<ul id="images">
<li class="other-image" style="display: none;">
<a target="_blank" href="http://www.example.com/page.html">
<img src="http://www.test.com/home/pic.jpg">
</a>
</li>
<li class="other-image" style="display: none;">
<a target="_blank" href="http://www.exmaple.com/index.html">
<img src="http://www.example-image.com/image.jpg">
</a>
</li>
<li class="other-image" style="display: none;">
<a target="_blank" href="http://www.example1.com/test">
<img src="http://www.example-image1.com/image1.jpg">
</a>
</li>
</ul>
$(document).ready(function () {
$("#images").find("li").fadeIn().delay(10000).fadeOut();
});
例如,我想显示href="http://www.exmaple.com/index.html" 所在的项目。我不想改用索引,因为随着从列表中添加/删除更多项目,该项目可能具有不同的索引。我尝试了几种不同的方式(如下)编写选择器,以仅选择具有此特定 href 值的列表项,但没有成功。
尝试 #1:
$("#images").find("li").filter($("a[href='http://www.exmaple.com/index.html']")).fadeIn().delay(10000).fadeOut();
尝试 #2:
$("#CCCImages").find($("a[href='http://www.exmaple.com/index.html']")).fadeIn().delay(10000).fadeOut();
尝试 #3:
$("#CCCImages").children($("a[href='http://www.exmaple.com/index.html']")).fadeIn().delay(10000).fadeOut();
任何建议将不胜感激。
【问题讨论】:
-
+1 表示作为新用户并在询问之前先尝试自己解决问题
标签: javascript jquery jquery-selectors