jQuery扩展$.fn、$.extend jQery命名方法扩展 练习总结

<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>
posted @ 2014-05-04 11:23  刘金宇  阅读(267)  评论(0编辑  收藏  举报