我需要制作一个jQuery增量/减量循环。
因此,我在此处发布了原始JavaScript,任何人都可以帮我将其更改为jQuery代码。
var incomeTicker = 60;
window.setInterval(function(){
if (incomeTicker > 0){
incomeTicker--;
document.getElementById("incomeTicker").innerHTML = "Next Profit In : " + incomeTicker + " seconds";
// other code implemented as long as incomTicker > 0
}
if (incomeTicker <= 1){
//code that is implemented when incomeTicker <=1
incomeTicker = 60;
//code that is implemented when incomeTicker <=1
}
}, 1000);
<span class = "incomeTicker" id = "incomeTicker" > Next Profit In : 100 seconds</span>
谁能帮忙将其翻译成jQuery吗?它必须递减,然后在循环完成后重置,如代码片段所示
最佳答案
在这里,您需要解决方案https://jsfiddle.net/vh0obhz6/
var incomeTicker = 60;
window.setInterval(function(){
if (incomeTicker > 1){
incomeTicker--;
$("#incomeTicker").html(`Next Profit In : ${incomeTicker} seconds`);
}else{
incomeTicker = 60;
}
}, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class = "incomeTicker" id = "incomeTicker" > Next Profit In : 100 seconds</span>