简介
jquery对象级别的插件开发,对于一些jquery中没有的方法,我们可以自己进行封装
方法
index.js
javascript">$(function(){
$("#btn").click(function(){
alert($("#d1").color());
//$("#d1").css("color","red");
//document.getElementById("d1").style.color="red";
})
})
function test(){
document.getElementById("d1").style.color="red";
}
jquery-color.js
javascript">(function($){
$.fn.color=function(value){
if(value==undefined)
return $(this).css("color");
else
$(this).css("color",value);
}
})(jQuery);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/jquery-3.6.3-min.js"></script>
<script src="js/index.js"></script>
<script src="js/jquery-color.js"></script>
</head>
<body>
jquery插件:<br />
<input type="button" id="btn" value="颜色" />
<div id="d1" style="color: red;">
颜色改成红色
</div>
</body>
</html>