<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>toggle事件示例</title>
<style type="text/css">
#div1 {
font-size: 9pt;
background-color: #9FF;
height: 300px;
width: 400px;
border: 1px solid #000;
}
</style>
<script type="text/javascript" src="jQuery/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function (e) {
//鼠标单击时改变背景颜色
$("#div1").toggle(
//第1次单击更改为绿色
function () {
$(this).css("background-color", "green");
},
//第2次单击更改为红色
function () {
$(this).css("background-color", "red");
},
//第3次单击更改为黄色
function () {
$(this).css("background-color", "yellow");
}
);
});
</script>
</head>
<body>
<div id="div1">单击这里更改颜色</div>
</body>
</html>
点击div没有变色是什么原因造成的
用旧版jquery,或者使用jQuery Migrate插件