编写一个jQuery的扩展方法(插件)

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<style type="text/css">

#a{

background: red;

}

</style>

</head>

<body>

<div id="a"></div>

</body>

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

<script type="text/javascript">

jQuery.fn.extend({

setWidth:function(){

$(this).width(200);

$(this).height(300);

return this;

}

});

$("#a").setWidth();

</script>

</html>

posted @ 2016-08-25 11:20  Milk.╮  阅读(255)  评论(0编辑  收藏  举报