【发布时间】:2014-10-22 03:44:46
【问题描述】:
我被这个难住了,非常感谢有人的帮助。
我正在自定义 highslide 以与 wordpress 集成。通过 highslide.config.js 文件中的以下代码,我将类名添加到某些元素,并根据某些条件通过 onClick 调用传递不同的属性。
在我添加以下代码之前一切正常:
if(hsGroupByWpGallery){
slideshowGroup: this.parentNode.parentNode.parentNode.id
};
当上面的代码出现时,不仅那条语句没有执行,而且整个事情都停止了工作。即使 if 语句类似于 if(1=1){};还是坏了。
如果我只是使用 slideshowGroup: this.parentNode.parentNode.parentNode.id 或什么都没有(我正在寻找的两个选项),那么两者都符合我的预期。我只需要一个 if 语句来在它们之间切换。
以下是相关代码:
jQuery(document).ready(function() {
var hsCustomGalleryGroupClass = 'fbbHighslide_GalleryGroup';
var hsCustomGalleryGroupChecker = 0;
var hsGroupByWpGallery = true;
jQuery('.' + hsCustomGalleryGroupClass).each(function(){
hsCustomGalleryGroupChecker++;
return false;
});
if (hsCustomGalleryGroupChecker > 0){
jQuery('.' + hsCustomGalleryGroupClass).each(function(i, $item) {
var grpID = $item.id;
jQuery('#' + grpID + ' .gallery-item a').addClass('highslide').each(function() {
this.onclick = function() {
return hs.expand(this, {
slideshowGroup: grpID
});
};
});
});
} else {
jQuery('.gallery-item a').addClass('highslide').each(function() {
this.onclick = function() {
return hs.expand(this, {
// This is the problem if statement
if(hsGroupByWpGallery){
slideshowGroup: this.parentNode.parentNode.parentNode.id
};
});
};
});
};
});
提前致谢。
【问题讨论】:
-
您添加的代码无法解析...这是无效的语法。
:应该是=或其他东西。我不确定这里的目标是什么。 -
你的意思是
slideshowGroup = this.parentNode.parentNode.parentNode.id -
什么是幻灯片组?您不能使用 ':' 分配变量,这种类型的分配在对象文字中使用,例如 {key: valye}
-
哦....所以基于其他代码...您没有复制您的
{ brackets }或它传递给...或返回语句的函数。
标签: javascript jquery wordpress highslide