修改脚本以检查数据相关
Modify script to check for a data-rel
我正在尝试修改此脚本以检查锚标记是否不包含 prettyPhoto[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"]')
对于data-rel
$('a[href*=".jpg"][data-rel], a[href*=".jpeg"][data-rel], a[href*=".png"][data-rel], a[href*=".gif"][data-rel]')
或者,如果您需要 or 条件,您可以修改if 条件为 :
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]'))
和 for 或条件:
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
相关文章:
- 如何检查Json文件更新,如果更新了,则用更新的数据刷新我的页面
- 如何检查数据库中的重复数据
- 正在检查ajax响应中的错误数据
- 将数据作为字符串从C#发送到Javascript-如何检查字符串
- 如何在angularjs中检查Kendo树视图数据绑定事件
- jQuery代码,用于在检查行时获取其他列的数据
- Javascript检查表单的当前数据是否等于其原始数据
- 在文本区域检查电子邮件数据时出现奇怪的jquery错误
- 如何检查数据表是否有任何包含字符串的行并获取它的行索引
- 当我单击它时,没有检查带有数据切换=选项卡的单选按钮
- 检查从ajax/php返回的数据
- 有没有一种方法可以在Typescript中自动检查数据类型的数据相等性
- 当chrome检查器为jQuery变量返回[object object]时,如何返回实际数据
- 用ng重复填充表,并检查匹配的表头数据
- 当通过Jquery data()附加时,以及当直接通过HTML中的数据属性附加时,检查HTML元素中的数据()
- 检查给定的数据列表中是否存在表单字段值
- 在动态更改数据之后(在ajax调用之后)检查函数是否存在
- 键入时检查输入中的重复数据
- 正在检查没有值的HTML5数据属性
- 数据检查欧芹不起作用