[英]Javascript If statement in a For loop working in Chrome and Safari but not Firefox
I am in the process of learning to code and building a picture gallery as part of the learning process for a TeamTreehouse.com contest. 作为TeamTreehouse.com比赛学习过程的一部分,我正在学习编码和建立图片库。
Here is the code: http://jsfiddle.net/kylenoble/8Wf8r/ and the result when running the code: http://jsfiddle.net/kylenoble/8Wf8r/embedded/result/ . 这是代码: http : //jsfiddle.net/kylenoble/8Wf8r/和运行代码时的结果: http : //jsfiddle.net/kylenoble/8Wf8r/embedded/result/ 。
The issue I am running into is clicking an .i
div that is nested in an .item
div. 我遇到的问题是点击了
.i
嵌套在一个DIV .item
股利。 After hours of banging my head into a wall, I have narrowed it down to the if
statement below triggering in Chrome and Safari but not triggering in Firefox. 经过数小时的努力,我将其范围缩小到下面的
if
语句,该语句在Chrome和Safari中触发,但在Firefox中不触发。
Here is the specific code: 这是特定的代码:
//Loops through the infoUrl's and populates the info button with
//infoUrl that matches the imageUrl
for(i = 0, len = (picturesList.length - 1); i <= len; i ++) {
var infoUrl = picturesList[i].infoUrl;
var imageUrl = picturesList[i].imageUrl;
var displayImage = 'url(' +imageUrl+ ')';
var currentItemUrl = ($(this).css('background-image'));
//Matches the imageUrl in the displayImage var with the
//corresponding infoUrl and opens the matched infoUrl when
//the 'info' button is clicked.
if (displayImage === currentItemUrl) {
console.log('true');
$('.i').click( function(event) {
window.open(infoUrl);
event.stopImmediatePropagation();
});
break;
}
}
I can't seem to figure out why the if
statement won't trigger in Firefox but will in Chrome and Safari. 我似乎无法弄清楚为什么
if
语句不会在Firefox中触发,而会在Chrome和Safari中触发。 I really appreciate any help you might be able to provide and I apologize if I've been unclear at any point in this question. 非常感谢您可能提供的帮助,如果对此问题尚不清楚,我们深表歉意。
Thank you! 谢谢!
I've checked in the debugger in Firefox, and it's showing a difference between displayImage
and currentItemUrl
. 我已经检查了Firefox中的调试器,它显示了
displayImage
和currentItemUrl
之间的区别。
currentItemUrl: "url("http://media.nara....ges/16/7/16-0651a.gif")"
currentItemUrl:
"url("http://media.nara....ges/16/7/16-0651a.gif")"
displayImage: "url(http://media.nara.g...ges/14/14/14-1336a.gif)"
displayImage:
"url(http://media.nara.g...ges/14/14/14-1336a.gif)"
Note the quotes. 注意引号。 I'm not sure why, but it seems Firefox returns the css property differently.
我不确定为什么,但是Firefox似乎以不同的方式返回了css属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.