【发布时间】:2015-05-25 23:09:38
【问题描述】:
如何调用在插件外部定义但在插件内部使用参数的函数函数。我在插件调用函数但参数未定义的地方有它。在插件内部,参数具有值。
(function ($) {
$.fn.myPlugin = function (options) {
var defaults = {
type: 0,
callBack: function () { }
};
var settings = $.extend({}, defaults, options);
this.find('.list-item').click(function (e) {
e.preventDefault();
var txt = $(this).attr('href');
var id = txt.substring(1, txt.length);
settings.callBack.call(settings.type, id); // populated here
});
return this;
};
} (jQuery));
function loadData(type, id) {
// type and id are undefined
}
<script type="text/javascript">
$(document).ready(function () {
$("#mydiv").myPlugin({
type: 190,
callBack: function(){ loadData();}
});
});
</script>
【问题讨论】:
标签: jquery jquery-plugins jquery-callback