<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test jQuery Extend</title>
<script src="jquery-1.12.4.min.js"></script>
<script>
(function($){
/*类插件 usage: $.add(1,2) */
$.extend({
add: function(a,b){return a+b;},
minus: function(a,b){return a-b;}
});
/*实例插件 usage: $("#name").strlen() */
$.fn.extend({
strlen: function () {
return $(this).text().length;
}
});
})(jQuery);
$(function () {
console.log($.add(1,2));
console.log($.minus(1,2));
console.log('字符长度',$("#name").strlen());
});
</script>
</head>
<body>
<div id="name">abcd123中国</div>
</body>
</html>