jquery对象扩展小试

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>test</title>
</head>
<body>
<div class="ui-button" ></div>
</body>
<script type="text/javascript" src="js/jquery.js"></script>


<script type="text/javascript">
//定义扩展对象
var aaa=function ddd(str){
var def={
aaa:"aaaa",
bbb:function(){
var dh1=$("<button></button>");
dh1.attr("style","color:red;");
dh1.html(def.aaa);
$(".ui-button").append(dh1);
}
};//定义默认属性
if(str){//判断是否传入参数
$.extend(def,str);//扩展默认属性
}
def.bbb();//执行入口函数
};
$.fn.tree=aaa;//把对象加入jquery中
$(".ui-button").tree({aaa:"1111"});//执行函数
//$(".ui-button").tree({aaa:"1111",bbb:function(){alert("sb");}})//执行函数,扩展bbb函数
</script>
</html>
posted @ 2013-08-25 10:07  话里  阅读(114)  评论(0编辑  收藏  举报