在ajax调用之后重新初始化jquery插件

时间:2014-11-27 23:37:01

标签: javascript jquery ajax

我有一个插件,我试图在ajax调用后重新初始化javascript事件。完成方法后,所有事件都将丢失。

我正在尝试重新初始化init方法。

 function Plugin(element, options) {
 this.el = element;
 this.$el = $(element);
 this.settings = $.extend({}, defaults, options);
 this._name = pluginName;
 this.ns = '.myPluginName';
 this.init();
}

Plugin.prototype = {
init: function();

var bind = this;
var somelink = bind.$el.find('.mylink');

var functionstartshere = function(){
    // all the function starts here


    //after the ajax call the new page looses all the event handlers
    var jqxhr = $.ajax( "example.php" )
      .done(function() {
        //adding my function here
        //how do i re-initialize the events
        //how do I call the init/ functionstartshere to put the events back
      })
      .fail(function() {
        alert( "error" );
      })    

}

some.on("click", functonstartshere);

0 个答案:

没有答案