我正在用mvc4做我的项目。我有一个Image文件夹,我想打开并使用jquery列出该文件夹中的所有图像。我为此写了以下jquery ajax代码
$(document).ready(function () {
var URL = "../Home/Show?foldername=DGInstallation";
$.ajax({
url: URL,
success: function (data) {
$(data).find("a:contains(.jpg)").each(function () {
var images = $(this).attr("href");
alert(images); //i want to get the particular image name, but this is not working
});
}
});
});
这里的数据包含整个html文件,我正在尝试检索jpg图像
<div id="galcontent">
<p style="padding:15px 10px 0 10px;"><a href="/Home/Gallery" style="text-decoration:underline;color:red;">Back to Gallery</a></p>
<a href="/Content/Gallery/GalleryImages/DGInstallation/afdgfd.jpg" rel="lightbox" data-lightbox="roadtrip"> <div class="thumb">
<img src="/Content/Gallery/GalleryImages/DGInstallation/afdgfd.jpg" /></div></a>
<a href="/Content/Gallery/GalleryImages/DGInstallation/gfdfutr.jpg" rel="lightbox" data-lightbox="roadtrip"> <div class="thumb">
<img src="/Content/Gallery/GalleryImages/DGInstallation/gfdfutr.jpg" /></div></a>
<a href="/Content/Gallery/GalleryImages/DGInstallation/gffg.jpg" rel="lightbox" data-lightbox="roadtrip"> <div class="thumb">
<img src="/Content/Gallery/GalleryImages/DGInstallation/gffg.jpg" /></div></a>
</div>
这些是图像以及我如何检索名称
答案 0 :(得分:0)
你可以尝试下面的代码,我已经创建了样本小提琴,你可以看一下: -
$("#galcontent").find('a[href$=".jpg"]').each(function () {
var images = $(this).attr("href");
alert(images); //i want to get the particular image name, but this is not working
});
演示: -