Да, из init проходит, а вот если из log вызвать log1 то получаю ошибку через this = Uncaught TypeError: this.log1 is not a function
Plugin.prototype = {
init: function (e) {
$(this.element).click($.proxy(this.click, this));
this.log('test');
},
click : function(e){
e.target.value = this.options.color;
},
log: function(msg) {
console.log(msg);
this.log1('test');
}
log1: function(msg) {
console.log(msg);
}
};
Цитата:
|
elink12,
строка 12, запятая где? |
Ночь, улица, фонарь, запятую забыл :) но это сути не поменяло. На jsfiddle создал , так же в консоли ошибка https://jsfiddle.net/9dykvku6/8/
<div id='alert'> 1.<input type="text"> </div> <div id='alert1'> 2.<input type="text"> </div>
(function($) {
var pluginName = 'Plugin',
defaults = {
color: "green",
},
options = {};
function Plugin( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
this.defaults = defaults;
this.name = pluginName;
this.input_name = $(element).attr('name');
this.init();
}
Plugin.prototype = {
init: function (e) {
$(this.element).on({"keyup" : this.log},"input",this.options);
},
log: function(msg) {
console.log(msg);
this.log1('test');
},
log1: function(msg) {
console.log(msg);
}
};
$.fn.Plugin = function ( options,event ) {
return this.each(function () {
new Plugin( this, options );
});
}
})(jQuery);
$( document ).ready(function() {
$('#alert').Plugin({color:'ааа'});
$('#alert1').Plugin({color:'red'});
});
|
elink12,
$(this.element).keyup($.proxy(this.log, this)) или
$(this.element).on({"keyup" : this.log.bind(this)},"input",this.options);
только у вас msg === event в log |
| Часовой пояс GMT +3, время: 20:27. |