简体   繁体   English

For循环中的Javas If语句可在Chrome和Safari中运行,但不能在Firefox中运行

[英]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中的调试器,它显示了displayImagecurrentItemUrl之间的区别。

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.

相关问题 Javascript在Safari中运行,但不适用于Chrome或Firefox - Javascript working in Safari but not Chrome or Firefox Javascript无法在浏览器中运行? (Firefox,Chrome和Safari) - Javascript not working in browser? (Firefox, Chrome and Safari) Javascript未在Firefox上执行,适用于Chrome和Safari - Javascript not executed on Firefox, working on Chrome & Safari Javascript / jQuery无法在Firefox,Safari和IE中运行。 精通Opera和Chrome - Javascript/jQuery not working in Firefox, Safari and IE. Fine in Opera and Chrome Javascript / JQuery突然在Chrome和Firefox中停止工作,但仍在Safari中工作 - Javascript/JQuery suddenly stops working in Chrome and Firefox, but still works in Safari Javascript(JS)应用程序可在Chrome上运行,但不能在mozilla firefox / safari上运行 - Javascript (JS) application working on Chrome but not on mozilla firefox/safari JavaScript代码仅在Chrome中有效,而在Firefox,IE,Opera和Safari中无效 - JavaScript code working only in Chrome but not in Firefox, IE, Opera and Safari JavaScript Ajax请求无法在Firefox和Google Chrome中运行,但在Safari中可以 - JavaScript Ajax request not working in Firefox and Google Chrome, but it is okay in Safari Javascript 表单验证代码适用于 FireFox 和 Chrome,但不适用于 Safari(在单选按钮上) - Javascript form validation code working on FireFox and Chrome but not on Safari (on radio button) Javascript 可以在 Chrome 和 Firefox 中运行,但不能在 Safari 中运行。 有任何想法吗? - Javascript working in Chrome and Firefox but not Safari. Any ideas?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM