您的位置:首页 > Web前端 > JQuery

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

2014-05-04 11:23 302 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: