jQuery 封装公共方法

  • my.js:封装方法的 JS
  • index.html:调用封装的公共方法

1、my.js

(function () {
    var requestURL = null;

    // 分页
    function bindPager() {
        // 事件委托,给idPagination(ul 标签) 下的 a 标签绑定 click 时间
        $('#idPagination').on('click', 'a', function () {
            var num = $(this).text();
            init(num);
        })
    }

    // jQuery 拓展了一个 NB() 方法
    jQuery.extend({
        'NB': function (url) {
            requestURL = url;
            bindPager();
        }
    });

})();

2、index.html

<script src="/static/js/extendJs.js"></script>
$(function () {
    $.NB('/app/v1/admin/');
})
原文地址:https://www.cnblogs.com/midworld/p/13610921.html