-2
我有两个功能,x()
和'Y(),点击其按钮,buttonX和buttonY他们两个调用,并呼吁暂停实际行动停止两个功能有超时。我想达到什么:启动和使用两个按钮
- 当buttonX被点击,功能
y()
不执行任何更长的时间,并且功能x()
被称为 - 有超时; - 当按钮Y被点击时,功能
x()
不再执行,并且函数y()
被调用 - 带有超时;
该怎么办?
HTML
<button onclick = "x()">button1</button>
<button onclick = "y()">button2</button>
JS
function x(){
// dosomething;
// stop execution of y()
setTimeout(x,2000);
}
}
function y(){
// dosomeother thing;
// stop execution of x()
setTimeout(y,2000);
}
请添加代码,你必须在这里看看,太:MCVE] –
尝试设置变量'timeoutX = setTimeout的()',那么你可以通过调用取消' clearTimeout(timeoutX)'。对于timeoutY可以做同样的事情。 –