jQuery扩展现有功能 [英] Jquery Extend Existing Function

查看:111
本文介绍了jQuery扩展现有功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种扩展现有Jquery函数以为其提供更多选项/参数的方法.

I am looking for a way to expand an existing Jquery function to give it more options/parameters.

我要使用的是$ .ajax,但这可以应用于任何jquery函数.

The one I want to use is $.ajax but this could apply to any jquery function.

我希望能够调用这样的函数:

I want to be able to call a function like this:

$.adv_ajax()

这将是$ .ajax函数的扩展版本,如下所示:

Which would be an extended version of the $.ajax function like as follows:

 $.adv_ajax({
  custom_parameter: "abc", //my custom one
  url: "test.html",
  context: document.body,
  success: function(){
    $(this).addClass("done");
  }
});

推荐答案

然后将函数附加到jQuery对象:

Well then just attach your function to the jQuery object:

$.adv_ajax = function(options) {
    // Do stuff like change some options and then call the original
    return $.ajax(options);
}

这篇关于jQuery扩展现有功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆