我想在JavaScript中的另一个函数中停止函数的循环.这是我试过的代码:
<a onmousedown="startLoop();" onmouseup="stopLoop();" >
Start loop
</a>
<script>
var static loop = 1;
function startLoop() {
while(loop ==1) {
}
alert("stop"); //This line is not executed
}
function stopLoop() {
loop = 2;
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是小提琴:http: //jsfiddle.net/A5h8k/4/