<script>
$.fn.hello =
function(){ //扩展jQuery实例的自定义方法,基于$.fn的jq方法扩展
this.click(function(){
alert(‘hello‘);
})
}
$(‘input‘).hello();
// 点击input正确出弹窗 ‘hello‘
</script>
<script>
$.fn.extend({
//用extend扩展jQuery实例的自定义方法
hello:function(){
this.click(function(){
alert(‘hello‘);
})
}
})
$(‘input‘).hello();
// 点击input正确出弹窗 ‘hello‘
</script>
<script>
$.fn.extend({ //extend扩展jq实例的
‘属性’
hello:‘hello‘,
})
var
obj = new $; //创建以jq为构造原型的 实例obj
document.write(obj.hello)
//打印字符串“hello“
</script>
<script>
$.extend({
//扩展jQuery这个全局对象的自定义方法
hello:function(){
$(‘input‘).click(function(){
alert(‘hello‘);
})
}
})
$.hello();
// 点击input正确出弹窗 ‘hello‘
</script>