gpt4 book ai didi

javascript - 使用 jquery 阻止特定链接

转载 作者:行者123 更新时间:2023-11-28 05:01:00 24 4
gpt4 key购买 nike

在图库中,我想阻止某些缩略图通过灯箱展开其原始图片。图像没有 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>

如果我使用它,所有缩略图都会被屏蔽。我怎样才能防止只阻止图片并避免阻止缩略图。是否可以将所有应被屏蔽的图像保存在一个数组中并循环遍历该数组以屏蔽这些缩略图?

最佳答案

您首先要检查是否存在带有 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;
});
});

关于javascript - 使用 jquery 阻止特定链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15268023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com