1.jQuery 是一个JS 类;
2.jQuery=$;
3.jQuery.extend(obj)就是为jQuery 添加一个静态方法。
$.extend({[color=red]constantmethod[/color]:function.......})
jQuery.extend({
doAlert:function(){alert("Morning!");}
});
jQuery.extend({
doSumAlert:function(a,b){alert(a+b);}
});
$.doAlert();
$.doSumAlert(100+200);
4.jQuery.fn=jQuery.prototype;
jQuery.fn.extend(obj)就是为jQuery添加一个成员函数,即对jQuery.prototype进行扩展。之后jQuery的实例或者说jQuery类的实例就可以使用这个成员函数。
比如我们借助jQuery开发一个我们自己的插件,功能:其中有一个编辑框,点击它时便先alert中当前编辑框中内容。
我们的HTML:
<input type='text' id='specialtextbox'/>
我们自己的js文件中就可以写为:
$.fn.extend({
doAlertWhileClick:function(){
$(this).click({alert($(this).val());})
}
})
$('#specialtextbox').doAlertWhileClick();
[b][color=blue]$('#specialtextbox')为一个jQuery实例[/color][/b],当它调用成员方法 alertWhileClick后,便实现了扩展,每次被点击时它会先弹出目前编辑里的内容。
jQuery提拱了丰富的操作文档,事件,CSS ,Ajax、效果的方法,结合这些方法,便可以开发出更加 Niubility 的插件。
2.jQuery=$;
3.jQuery.extend(obj)就是为jQuery 添加一个静态方法。
$.extend({[color=red]constantmethod[/color]:function.......})
jQuery.extend({
doAlert:function(){alert("Morning!");}
});
jQuery.extend({
doSumAlert:function(a,b){alert(a+b);}
});
$.doAlert();
$.doSumAlert(100+200);
4.jQuery.fn=jQuery.prototype;
jQuery.fn.extend(obj)就是为jQuery添加一个成员函数,即对jQuery.prototype进行扩展。之后jQuery的实例或者说jQuery类的实例就可以使用这个成员函数。
比如我们借助jQuery开发一个我们自己的插件,功能:其中有一个编辑框,点击它时便先alert中当前编辑框中内容。
我们的HTML:
<input type='text' id='specialtextbox'/>
我们自己的js文件中就可以写为:
$.fn.extend({
doAlertWhileClick:function(){
$(this).click({alert($(this).val());})
}
})
$('#specialtextbox').doAlertWhileClick();
[b][color=blue]$('#specialtextbox')为一个jQuery实例[/color][/b],当它调用成员方法 alertWhileClick后,便实现了扩展,每次被点击时它会先弹出目前编辑里的内容。
jQuery提拱了丰富的操作文档,事件,CSS ,Ajax、效果的方法,结合这些方法,便可以开发出更加 Niubility 的插件。