jQuery递减循环

jQuery Decremental Loop

我需要制作一个 jQuery incremental/decremental 循环。

所以我在这里发布原版 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>

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);

你应该多用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>