<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" src="jquery.js"></script> <!-- 此处的jquery必须是带有toggle额外功能的库 (百度云里有这个库)-->
</head>
<body>
<button>请点击这里,来切换不同的背景颜色</button>
<p>给这段文字切换不同的背景颜色</p>
<script type="text/javascript">
$(function(){
$("button").toggle(
function(){$("p").css("color","red")},
function(){$("p").css("color","green")},
function(){$("p").css("color","yellow")}//此处不能加逗号
);
});
</script>
</body>
</html>
时间: 2024-10-05 05:18:53