(function($) {
var defaults = {
myId:0
}; $.fn.myFoo = function(settings) {
var opts = $.extend({},defaults, settings || {});
//var self = $(this); function myFoo(settings){
return this;
}; myFoo.prototype = {
callMe:function(){
alert('here');
}
};
};
})(jQuery);我初学写JQ插件,不知道这样形式有没有错,大家可以提供下各自的JQ插件写法给我参考下.
求教怎么编写这样模式的JQ插件呢?
解决方案 »
- 为什么一个js代码,在普通浏览器可以,但是在(360极速浏览器)Chrome浏览器下就不可以使用!
- this.initialize.apply(this, arguments);理解下帮忙。
- 如何在标签p中实现document.write?
- insertBefore
- jquery 事件更换问题
- ie10无法获通过iframe.contents().find("body").height()获取隐藏iframe的高度,大神怎么处理?膜拜了
- 怎么把input中的内容向上对齐?!
- 在netscape6中动态增加单元格没有反应?
- 如何去空格?急急,在线等待
- 存在frameset A 好含两个frame B 和C 怎么在B中js实现A的跳转 求秒
- 使用owc控件的Export方法时报错提示无法保存文件
- doucument 获取不到div的id
再就是prototype和原型链作用域如果真有心学习的话有两本好书
JavaScript基础 《JavaScript高级程序设计》,第二版就很好,第三版介绍了很多HTML5,ECMAScript5,现在还用不到,反而不好编写自己的库和插件 《JavaScript DOM高级程序设计》这本书不好买,下个电子版的
扩展插件就这两种写法吧
扩展插件就这两种写法吧
<head>
<title> jQuery plugin test </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
input { border:solid 1px #7F9DB9; }
.error { border:solid 1px red; }
</style>
<script type="text/javascript" src="jquery.1.4.2.src.js"></script>
<script type="text/javascript">
(function($) { // 增加红色边框的插件
$.fn.error = function(clazz) {
return this.each(function() {
$(this).addClass(clazz || "error");
});
};
})(jQuery);
jQuery(function($) {
$("button").click(function() { // 设置边框
$("input[type=text]").error();
});
});
</script>
</head>
<body>
<p><input type="text" name="account" /></p>
<p><input type="text" name="password" /></p>
<p><button name="action">click me!</button></p>
</body>
</html>
(function($) {
$.fn.xxx = function() {
return this.each(function() { // 这样写才能遍历执行
});
};
})(jQuery);