2017-01-23 34 views
-8

100計數此刻,我可以把它我點擊的my fiddle shows每次算一個接一個。以下是我的html。如何從從0上升jQuery中

var count = 0; 
 

 
$("#update").click(function() { 
 
    count++; 
 
    $("#counter").html("My current count is: " + count + "%"); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<button id="update" type="button">Button</button> 
 
<div id="counter">1</div>

如何我居然只有一次點擊一個按鈕,使該縣從0到100%?

+0

'count <100 && count ++;',我想你想限制計數 –

+0

您是否問過一個「動畫序列」,只需點擊一次即可快速從0運行到100? – Thilo

+0

@Thilo。是的,我只是重述了這個問題。 –

回答

4

計數從0到100%,您可以使用setInterval以延遲更新文本。

$("#update").click(function() { 
 
    var count = 0; 
 
    var innterval = setInterval(function() { 
 
    if (count == 100) 
 
     clearInterval(innterval); 
 
    count++; 
 
    $("#counter").html("My current count is: " + count + "%"); 
 
    }, 1000); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<button id="update" type="button">Button</button> 
 
<div id="counter">1</div>

+0

它完全符合我的要求。感謝支持 –

0

不知道這是否是你想要的,但如果你想你的計數去從0到每次100,然後簡單地改變從上

count++; 

count+=100; 
0

我想你想從0循環到100請查看以下鏈接給你:

http://jsfiddle.net/fatehjagdeo/Bwdfw/312/

或請參閱下面的代碼:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script> 
<button id="update" type="button">Button</button> 
<div id="counter"></div> 

<script> 
$("#update").click(function() { 
for(var i=1;i<=100;i++){ 
    $("#counter").append("My current count is: "+i +"%<br>"); 
} 


}); 
</script>