jquery 点击同一个按钮,第一次与第二次执行不同事件,循环执行事件一与事件二!
var f = false;
$(".box").click(function(){
if(f = !f){
alert(1)
}else{
alert(2)
} });
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style type="text/css">
.box{
width: 100px;
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
<script src="jquery.min.js"></script>
<script>
$(function(){
var f = false;
$(".box").click(function(){
if(f = !f){
alert(1)
}else{
alert(2)
}
});
});
</script>