简体   繁体   中英

Setting option for jQuery plugin

I'm working on a jQuery plugin and i have many things figured out including how to set options. But theres one thing about adding options to my plugin that i'm not clear about. I know that i can create options by doing this

    var options = $.extend ({
        spacing: 30,
        TopSide: true,
    }, options);

I would use the first option like this

    $(this).css({"top": defaults.spacing});

But i;m not sure how to use options that have "true", or "false" values. How to i have something happen when its set to true?

// for assigning
var someValue = options.TopSide ? this1() : that1();

// for do stuff
options.TopSide ? doThis() : doThat();

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