编写一个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>

原文地址:https://www.cnblogs.com/luckyXcc/p/5806043.html