简体   繁体   中英

Testing for a true, and a false condition in modernizr.load

I have 3 test conditions for Modernizr.load.

  • If A is false, I load A.js
  • If B is false, I load B.js
  • If both A and B are true, and C is false, I load C.js

Currently if A, B, and C are all false, then they are all loaded, whereas I only want A and B to be loaded.

How can I test for both true and false conditions in the same "test:"?

My code looks like:

Modernizr.load([
    {
        test: Modernizr.A,
        nope: 'A.js'
    },
    {
        test: Modernizr.B,
        nope: 'B.js'
    },
    {
        test: !Modernizr.A && !Modernizr.B && Modernizr.C,
        nope: 'C.js'
    }
]);

I was able to accomplish this like so:

Modernizr.load([
    {
        test: Modernizr.A,
        nope: 'A.js'
    },
    {
        test: Modernizr.B,
        nope: 'B.js',
        complete: function() {
            if ( Modernizr.A && Modernizr.B ){
                Modernizr.load({
                    test: Modernizr.C,
                    nope: 'C.js'
                });
            }
        }
    }
]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM