setInterval()方法
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="jquery.js"></script>
<style>
.blue{
width: 200px;
height: 200px;
background-color: blue;
}
.red{
width: 200px;
height: 200px;
background-color:red;
}
</style>
</head>
<body>
<input class="ting" type="button" value="停止">
<input class="kai" type="button" value="开始">
<div class="blue"></div>
<script type="text/javascript">
var intervar = setInterval(function(){
$("div").toggleClass("red");
},100);
$(function(){
$(".ting").on("click",function(){
clearInterval(intervar);
});
});
$(function(){
$(".kai").on("click",function(){
setInterval(function(){
$("div").toggleClass("red");
},100);
});
});
</script>
</body>
</html>
功能