Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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 修改脚本以检查数据关系_Javascript_Jquery - Fatal编程技术网

Javascript 修改脚本以检查数据关系

Javascript 修改脚本以检查数据关系,javascript,jquery,Javascript,Jquery,我正在尝试修改此脚本,以检查锚定标记是否不包含到[product gallery]的数据rel 我尝试过几次在第3行添加|,但都没有成功。任何帮助都将不胜感激 $('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"]').each(function(){ //single image popup if ($(this).parents('.iwmp-gallery').length == 0) { /

我正在尝试修改此脚本,以检查锚定标记是否不包含
到[product gallery]
的数据rel

我尝试过几次在第3行添加
|
,但都没有成功。任何帮助都将不胜感激

$('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"]').each(function(){
  //single image popup
    if ($(this).parents('.iwmp-gallery').length == 0) { //Line #3
      $(this).magnificPopup({
        type:'image',
          callbacks: {
            open: function() {
             $('.mfp-description').append(this.currItem.el.attr('alt'));
},
                          afterChange: function() {
                            $('.mfp-description').empty().append(this.currItem.el.attr('alt'));
                          }
                        },
                            image: {
                                markup: 
                                '<div class="mfp-figure">'+
                                '<div class="mfp-close"></div>'+
                                '<div class="mfp-img"></div>'+
                                '<div class="mfp-bottom-bar">'+
                                '<div class="mfp-title"></div>'+
                                '<div class="mfp-description"></div>'+
                                '<div class="mfp-counter"></div>'+
                                '</div>'+
                                '</div>',
                                titleSrc: function(item) {
                                    return item.el.find('img').attr('alt');
                                }                           
                            }
                        });
                    }
                });
$('a[href*=“.jpg”]、a[href*=”.jpeg”]、a[href*=“.png”]、a[href*=”.gif”])。每个(函数(){
//单个图像弹出窗口
if($(this).parents('.iwmp gallery').length==0){//Line#3
$(此).magnificPopup({
类型:'image',
回调:{
打开:函数(){
$('.mfp description').append(this.curroItem.el.attr('alt'));
},
后更改:函数(){
$('.mfp description').empty().append(this.curroItem.el.attr('alt'));
}
},
图片:{
标记:
''+
''+
''+
''+
''+
''+
''+
''+
'',
标题RC:功能(项目){
返回项.el.find('img').attr('alt');
}                           
}
});
}
});

谢谢

您可以修改选择器

$('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"]') 
对于
数据rel

$('a[href*=".jpg"][data-rel], a[href*=".jpeg"][data-rel], a[href*=".png"][data-rel], a[href*=".gif"][data-rel]')
或者,如果需要或条件,可以修改 如果条件为:

if (($(this).parents('.iwmp-gallery').length == 0)||$(this).attr("data-rel"))
参考:

对于非数据相关:

$('a[href*=".jpg"]:not([data-rel]), a[href*=".jpeg"]:not([data-rel]), a[href*=".png"]:not([data-rel]), a[href*=".gif"]:not([data-rel]'))
以及针对或条件:

if (($(this).parents('.iwmp-gallery').length == 0)||(!$(this).attr("data-rel").length))
答案是

if (($(this).parents('.iwmp-gallery').length == 0)||(!$(this).attr("data-rel").length))

感谢@KK

第3行不清楚。你能用注释来标记吗?我现在已经标记了第3行。谢谢你。。我意识到我的问题是不正确的,我已经更新了上面的问题。我想检查它是否不包含数据rel。很抱歉谢谢你的帮助。