简体   繁体   中英

how to solve this complex if-statement in Javascript/Jquery?

I need to exclude elements from a function and am struggling with the if-clause...

I can have four type of elements with three attributes

             A                  B               C          D
-----------------------------------------------------------------
"external"   undefined     boolean/undefined   boolean     boolean
"wrapper"    boolean       undefined           boolean     undefined
"parent"     1             0                   1          1

I need to construct an if-clause that only allows A and B to pass and I'm going insane...

Here is what I have:

// "from" is my element to check
if ( 
   ( typeof from.jqmData("external-page") == "undefined" 
            && from.parents('body').length == 1 ) 
     || 
   ( typeof from.jqmData("external-page") == "boolean" 
             && from.parents('body').length == 0 )
   ) {
     // do something    
     }

Can someone help me out and get me on the right track?

Thanks!

Will this work:

if (from.parents('body').length === 0 || typeof from.jqmData('external-page') === 'undefined') {
    // do something
}

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