我非常喜欢这个,非常感谢别人的帮助。if function within function breaks javascript
我正在定制与wordpress集成的highslide。通过highslide.config.js文件中的以下代码,我为某些元素添加一个类名,并根据特定条件通过onClick调用传递不同的属性。
一切正常,直到我添加以下代码:
if(hsGroupByWpGallery){
slideshowGroup: this.parentNode.parentNode.parentNode.id
};
当上面的代码存在,不仅是一个语句不执行,但整个事情停止工作。即使if语句像if(1 = 1){};它仍然打破。
如果我只是幻灯片组: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
};
});
};
});
};
});
在此先感谢。
您添加的代码不会解析...它是无效的语法。 ':'应该是一个'='或其他东西。我不确定这里的目标是什么。 – 2014-10-22 03:47:33
您的意思是'slideshowGroup = this.parentNode.parentNode.parentNode.id' – 2014-10-22 03:48:04
什么是slideshowGroup?你不能用一个':'赋值变量,这种类型的赋值在对象字面量内使用,例如,{key:valye} – 2014-10-22 03:49:07