index.html:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1-10-1.js"></script>
<script type="text/javascript" src="jquery-ui-1-9-2.js"></script>
<script>
$(document).ready(function(){
$("#button1").click(function(){
$("#div").css("background","red");
//some code here
});
});
$(function (){
function first(){
$("#div").css("background","red");
$(this).one("click",second);
}
function second(){
$("#div").css("background","blue");
$(this).one("click",first);
}
$("#button2").one("click",first);
});
</script>
</head>
<body>
<input type="button" id="button1" value="button1"></input>
<input type="button" id="button2" value="button2"></input>
<div id="div">some text</div>
</body>
</html>
当我点击button1时,我应该将一些代码放入
$(“#button2”)。one(“click”,first); 变为 $(“#button2”)。one(“click”,second); < /强>
答案 0 :(得分:1)
您需要unbind
现有的one
点击事件并设置新的one
$("#button2").unbind("click");
$("#button2").one("click",second);
这应该解开第一个并绑定第二个。
$("#button1").click(function(){
$("#div").css("background","red");
$("#button2").unbind("click");
$("#button2").one("click",second);
});