Nová ukázka
Reset
Načíst z URL
Uložit a získat odkaz
Vztahuje se k…
Nevyplňujte
Napiště „nejsem robot“
▶
Přepnout zobrazení
Výsledek
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> </head> <body> <h3>First plugin</h3> <p>Some text 1</p> <p>Some text 2</p> </body> </html>
HTML
Autoformát
Standardní režim
Mobilní zobrazení
CSS
Autoformát
CSS reset
Až na konci
var $ = jQuery.noConflict(); var Plugin = function($self, options) { this.$self = $self; this.options = $.extend({}, $.fn.plugin.defaults, options); }; Plugin.prototype.init = function() { this.$self.css('color', this.options.color); }; Plugin.prototype.update = function(newText, author) { this.$self.html(newText, author); }; $.fn.plugin = function(option) { var options = typeof option == "object" && option; var data = arguments return this.each(function() { var $this = $(this); var $plugin = $this.data("plugin"); if (!$plugin) { $plugin = new Plugin($this, options); $this.data("plugin", $plugin); } if (typeof option == 'string') { $plugin[option].apply($plugin, Array.prototype.slice.call( data, 1 )); } else { $plugin.init(); } }); }; $.fn.plugin.defaults = { color: "black" }; var p1 = $('p').eq(0).plugin(); var p2 = $('p').eq(1).plugin({ color: 'red' }); p2.plugin('update', 'This is a new text', 'by some author');
J
ava
S
cript
Autoformát
jQuery
Umístění JS
window.onload
</head>
</body>