Creating custom jQuery function without selector prerequisite

后端 未结 3 1423
天涯浪人
天涯浪人 2020-12-30 06:00

I know that I can create custom jQuery plugins by using the $.fn.myFunction constructor, and the calling the custom function in JavaScript as $(\'selector

3条回答
  •  [愿得一人]
    2020-12-30 06:26

    (function ($) {
        $.MessageBox = function () {
            var show = function () {
                // something...
            }
            var hide = function () {
                // something...
            }
            return {
                show: show,
                hide: hide
            }
        }
    })(Jquery);
    

    I think you better scope to Immediate invocation function to avoid collision with namespaces.

提交回复
热议问题