我做插件:

$.widget("my.idautocomplete", $.ui.autocomplete, {

    options: {
        oldselect:{},
        id:""
    },
    _create: function () {
        $.ui.autocomplete.prototype._create.call(this);

        this.options.oldselect=this.options.select;
        this.options.select=this.sel;
    },

    sel:function (event, ui) {
        console.log("Autocomplete sel " + $(this).attr("id"));
    }
}

稍后我尝试将此选择用作:

$("input").idautocomplete({select:function(){alert(1);} });

然后替换此选择,我看不到消息... log(“自动完成选择...。此后,我的功能” sel“不起作用。我该如何在插件中写入我的选择内容并不会崩溃,然后将其替换为外部代码?

在代码中:

    $.widget("my.idautocomplete", $.ui.autocomplete, {

    options: {
        id:""
    },

    select:function (event, ui) {
        console.log("Autocomplete sel " + $(this).attr("id"));
    }
}

“选择”不起作用,然后在下拉列表中选择元素

===============>>#1 票数:0 已采纳

$.widget("my.idautocomplete", $.ui.autocomplete, {

    options: {
           oldselect:undefined,
           select:function sel_(event, ui) {
                    var th=this;
                     //some my plugin code
                     ...
                      // call select added from HTML programmer
                    $(th).idautocomplete("sel",event, ui);
            }
    },
    sel:function oldSel(event, ui) {
       var th=this;

        // if has external added select, call it
       var oldSelect = th.options.oldselect;
        if(oldSelect!==undefined){
            oldSelect.call(th,event, ui);
        }
    },

    _setOption: function () {
        if (arguments[0]=="select") {
           //getting a new onSelect function and save it in options
            this.options.oldselect=arguments[1];
             //save private plugin select
            var tst=this.options.select;
             // call _setOption to correct initialisation autocomplete
            $.ui.autocomplete.prototype._setOption.apply(this, arguments);
             // restore private select as default
            this.options.select=tst;
        }else{
            $.ui.autocomplete.prototype._setOption.apply(this, arguments);
        }
    },

.....

})(jQuery, window, document);

  ask by user2151099 translate from so

未解决问题?本站智能推荐: