jQuery 扩展
首先,得在html
文件内先引入jquery.min.js
文件;
然后再开始编写扩展。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
...
<div class="ui segment">
...
<button class="ui button">Button I</button>
<a id="qz-btn-demo">Button II</a>
</div>
...
<!-- MUST load jQuery first! -->
<script type="text/javascript" src="app/jquery.min.js"></script>
<script type="text/javascript">
// $.UIInit();
(function($) {
$.extend({
UIInit: function() {
console.log('UIInit() called');
}
});
// $(".class,#id").button();
$.fn.extend({
button: function(options) {
console.log('$.fn.Init() called', this);
this.each(function() {
$(this).attr('disabled', options.disabled);
});
return this;
}
});
}) (jQuery);
// HOWTO call: wjQuery start
$(function() {
$.UIInit();
$(".ui.button,#qz-btn-demo").button({ disabled: true });
});
</script>
</body>
</html>