首页 > Web开发 > 详细

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

时间:2014-05-04 20:09:09      阅读:515      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
<script>
$.fn.hello = function(){  //扩展jQuery实例的自定义方法,基于$.fn的jq方法扩展
    this.click(function(){
        alert(‘hello‘);
    })
}
$(‘input‘).hello();  // 点击input正确出弹窗 ‘hello‘
</script>
bubuko.com,布布扣
bubuko.com,布布扣
<script>
$.fn.extend({  //用extend扩展jQuery实例的自定义方法
    hello:function(){
        this.click(function(){
            alert(‘hello‘);
        })
    }
})

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

jQuery扩展$.fn、$.extend jQery命名方法扩展 练习总结,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/liujinyu/p/3706372.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!