我需要创建一个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吗?它必须递减,然后在循环完成后重置,如代码片段所示
发布于 2017-08-09 11:55:19
在这里,您可以使用解决方案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>
发布于 2017-08-09 12:22:48
你应该使用更多的jQuery,它可以做所有的事情。
下面是添加更多jQuery的方法
$.incomeTicker = 60;
(function rec() {
$.each((new Array($.incomeTicker)).fill(0), function(i) {
var sec = Math.abs(i - $.incomeTicker);
$('#incomeTicker').delay(1000).queue(function(n) {
$(this).html("Next Profit In : " + sec + " seconds");
n(); if (sec === 1) rec();
});
});
})();<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="incomeTicker"></div>
发布于 2017-08-09 11:56:57
var incomeTicker = 60;
window.setInterval(function(){
if (incomeTicker > 0){
incomeTicker--;
$("#incomeTicker").html("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);https://stackoverflow.com/questions/45581364
复制相似问题