我想知道如何在jquery脚本中创建一个If语句来检查源图像文件是否是某个文件,如果是,则在If语句中执行代码。我希望If Statement仅在source =
时执行其代码<%= Page.ResolveUrl("~/{0}/_res/_images/icon_noticeActive.png", PBS.Cms.Settings.PBSFolderName) %>". Here's my html code and jquery script below.
$("img#importantImg").click(function () {
if ($("#headerAlertMessage").is("<%= Page.ResolveUrl("~/{0}/_res/_images/icon_noticeActive.png", PBS.Cms.Settings.PBSFolderName) %>")
$("#headerAlertMessage").show();
$("#importantImg").attr("src", "<%=Page.ResolveUrl("~/{0}/_res/_images/icon_noticeActive.png", PBS.Cms.Settings.PBSFolderName) %>");
});
这是我上面引用的脚本的html代码:
<li class="levelOne" ><a class="button notice buttonEight" href="#">
<asp:image id="importantImg" runat="server" ClientIDMode="Static" /></a></li>
</ul>
<asp:PlaceHolder ID="contentPlaceholder1" runat="server" EnableViewState="false" />
</div>
<div id="headerAlertMessage" runat="server" ClientIDMode="Static" style="display:none">
<div id = "divLayer1" class="alertPod">
<img src="<%= Page.ResolveUrl("~/{0}/_res/_images/icon_alertMessage.png", PBS.Cms.Settings.PBSFolderName) %>" />
</div>
<div id = "divLayer2" class="msgPod">
<div id="divLayer3" class="messageWrapper">
<h6>IMPORTANT ANNOUNCEMENT</h6>
<div id="divLayer4" class="box" >
<div id = "divLayer5" class="viewport" style="overflow: auto; height: 48px;" runat="server">
<p>
<asp:Literal ID="ltimportantannouncementTitle" runat="server"></asp:Literal>
<br />
<asp:Literal ID="ltimportantannouncementSummary" runat="server"> </asp:Literal>
</p>
</div>
</div>
</div>
<a href="#" ><img id="alertCloseBtn" ClientIDMode="Static" src="<%= Page.ResolveUrl("~/{0}/_res/_images/button_alertMsgClose.png", PBS.Cms.Settings.PBSFolderName) %>" /></a>
</div>
</div>
答案 0 :(得分:0)
$('img[src="your_source_goes_here.jpg"]').each(function (index, value) {
//run your code here
});
这将找到具有特定源的所有图像,通过它们进行迭代,这使您可以在.each()
函数内执行任何操作。请注意,value
是保存.each()
函数中图像引用的变量。
以下是按来源选择图片的方法:http://jsfiddle.net/jasper/u5xWP/