i Bau Plugin wie folgt aus:Javascript initialisieren Ereignisse aus Variable
(function($){
var defaults = {
param1:null,
param2:null
};
var methods = {
init:function(params) {
var options = $.extend({}, defaults, params);
$(this).append('<button class="addbtn">Add elements</button>');
$(document).on('click','.addbtn',function(){
$('body').append(button.html+input.html);
});
}
};
var button = {
html: '<button class="btn">Button</button>'
};
var input = {
html: '<input type="text" class="input" value="" />'
};
var actions ={
clicked:function(){
alert('clicked');
},
hover:function(){
alert('hover');
}
};
$.fn.JPlugin = function(method){
if (methods[method]) {
return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method"' + method + '" is not found jQuery.mySimplePlugin');
}
};
})(jQuery);
$('body').JPlugin();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
auf Schaltfläche Hinzufügen Durch Klicken Sie Eingabe von input.html
und Knopf aus button.html
hinzufügen. Wie kann ich Click-Ereignis für Eingabeelement und Schaltfläche Objekte von actions.clicked
und Hover-Ereignis von actions.hover
Bitte klicken Sie auf den '<>' und erstellen [MCVE] – mplungjan