我有以下代码:
var thumbs = $("#thumbs img");
var links = $("#thumbs a");
这给了我两个变量,其中包含“thumbs”div ID 中的所有图像和链接。
我需要的是一个数组,其中包含像这样包裹在图像标签周围的链接:
<a href="www.google.com"><img src="image1.gif"></a>
这就是代码在“thumbs”div 中的样子。我应该使用 .children()
方法吗?如果可以,请给我举个例子。
谢谢!
最佳答案
您的确切需求尚不清楚,但看起来您想要
$("#thumbs a > img"); // images wrapped directly in links
或
$("#thumbs a:has(img)"); // the links around the images
关于javascript - 获取包含图像的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13193073/