Mar*_*rco 1 html javascript jquery
在图库中,我想阻止某些缩略图通过灯箱扩展其原始图片.图像没有ID,只有一个类.所有链接都从数据库中的表中读取.
$(document).ready(function(){
if($('.product-image').attr('target', 'blockedpath')) {
$('.product-image').click(function(e) {
e.preventDefault();
return false;
});
}
});
<li class="product">
<div class="productInfo">
<h3>@i.ToString()</h3>
<a href="@Href("~/Images/2013/" + i.ToString() + ".jpg")" rel="lightbox" class="link">
<img class="product-image" src="@Href("~/Images/2013/Thumbnails/" + i.ToString() + ".jpg")" alt="foto" />
</a>
</div>
</li>
Run Code Online (Sandbox Code Playgroud)
如果我使用它,所有缩略图都会被阻止.如何防止仅阻止图片并避免阻止缩略图.是否可以保存所有应该在数组中阻塞的图像并循环遍历该数组以阻止这些缩略图?
您首先检查是否存在任何图像target = blockedpath,然后阻止所有图像.
你可以使用这样的东西:
$(document).ready(function(){
// Select elements with the product-images class, that also
// have a target attribute with a value equal to 'blockedpath'
// Bind a click event to the matched elements
$('.product-image[target="blockedpath"]').click(function(event) {
event.preventDefault();
return false;
});
});
Run Code Online (Sandbox Code Playgroud)