[英]Javascript If statement in a For loop working in Chrome and Safari but not Firefox
作為TeamTreehouse.com比賽學習過程的一部分,我正在學習編碼和建立圖片庫。
這是代碼: http : //jsfiddle.net/kylenoble/8Wf8r/和運行代碼時的結果: http : //jsfiddle.net/kylenoble/8Wf8r/embedded/result/ 。
我遇到的問題是點擊了.i
嵌套在一個DIV .item
股利。 經過數小時的努力,我將其范圍縮小到下面的if
語句,該語句在Chrome和Safari中觸發,但在Firefox中不觸發。
這是特定的代碼:
//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;
}
}
我似乎無法弄清楚為什么if
語句不會在Firefox中觸發,而會在Chrome和Safari中觸發。 非常感謝您可能提供的幫助,如果對此問題尚不清楚,我們深表歉意。
謝謝!
我已經檢查了Firefox中的調試器,它顯示了displayImage
和currentItemUrl
之間的區別。
currentItemUrl: "url("http://media.nara....ges/16/7/16-0651a.gif")"
displayImage: "url(http://media.nara.g...ges/14/14/14-1336a.gif)"
注意引號。 我不確定為什么,但是Firefox似乎以不同的方式返回了css屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.