21. 使用css()方法直接设置元素样式

版权声明:本文为大都督作者的原创文章,未经 大都督 允许也可以转载,但请注明出处,谢谢! 共勉! https://blog.csdn.net/qq_37335220/article/details/84946072

1. 效果图

在这里插入图片描述

2. html代码

<!DOCTYPE html>
<html>
<head>
    <title>3.7 使用CSS()方法直接设置元素样式</title>
         <style type="text/css">
           body{font-size:15px}
           p{padding:5px;width:220px;cursor:pointer;}
    	</style>
</head>
<body>
	 <p>Write Less Do More</p>
	 
<script src="../jquery.min.js"></script>
<script type="text/javascript">
	$(function(){
		
		$("p").click(function() {
			//字体加粗
			$(this).css("font-weight", "bold");
			//斜体
			$(this).css("font-style", "italic")
			//增加背景色
			$(this).css("background-color", "#eee");
		})
		
	});
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_37335220/article/details/84946072
21.