我想要用户点击一个DIV元素,并让它在JavaScript中为变量加1,并且随着该变量值的变化发生不同的事情。当我第一次点击div元素时,它会显示“你在这里!”但是当我第二次点击div元素时......没有任何事情发生。看起来这个变量没有被更新。jQuery/JS - 变量似乎没有更新?
var $test = 0;
$(document).ready(function() {
if ($test == 0) {
$("#textbox").click(function() {
$(textbox).text("You and here!");
$test = $test + 1;
});
};
if ($test == 1) {
$("#textbox").click(function() {
$(textbox).text("Now, you are there!");
$test = $test + 1;
});
};
});
只是别人只.... –
咖啡@当测试成为2时,C链接不知道OP想要什么或更多:( –
可能是他''测试=测试 - 1;'''case test == 1'' – zzlalani