Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery阻止特定链接_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jquery阻止特定链接

Javascript 使用jquery阻止特定链接,javascript,jquery,html,Javascript,Jquery,Html,在图库中,我想阻止某些缩略图通过lightbox扩展其原始图片。 这些图像没有ID,只有一个类。所有链接都是从数据库中的表中读取的 $(document).ready(function(){ if($('.product-image').attr('target', 'blockedpath')) { $('.product-image').click(function(e) { e.preventD

在图库中,我想阻止某些缩略图通过lightbox扩展其原始图片。 这些图像没有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>
$(文档).ready(函数(){
if($('.product image').attr('target','blockedpath')){
$('.product image')。单击(函数(e){
e、 预防默认值();
返回false;
});
}
}); 
  • @i、 ToString()
  • 如果我用这个,所有的缩略图都会被阻塞。我如何防止仅仅是阻止图片和避免阻止缩略图。
    是否可以将所有应被阻止的图像保存在一个数组中,并通过该数组循环以阻止这些缩略图?

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

    首先检查是否存在带有
    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;
        });
    }); 
    
    或者相反:

    $('.product-image').not('[target=blockedpath]').click(function(){
      alert('hi!');
    });
    

    或者相反:

    $('.product-image').not('[target=blockedpath]').click(function(){
      alert('hi!');
    });
    

    您应该使用
    数据
    属性,而不是
    目标
    。通过使用此代码,您实际上是在强制将
    目标
    设置为所有
    产品图像的
    阻塞路径
    。您应该使用
    数据
    属性,不是
    target
    。通过使用此代码,实际上您强制将
    target
    设置为
    blockedpath
    ,用于所有
    。产品图像'
    添加了html/Razer标记。它不知何故不起作用。我想发布我的Razer标记,但编辑器除了一行c#代码外,将其全部吞没。每一张图片都保持可点击性我很懒,只是用foreach循环实现了一个if子句,在创建标记之前,迭代所有文件名以过滤掉它们。不知何故,它不起作用。我想发布我的Razer标记,但编辑器除了一行c#代码外,将其全部吞没。每个图片都保持可点击性我很懒,只是用foreach循环实现了一个if子句,在创建标记之前迭代所有文件名以过滤掉它们。