我試圖編寫一個點擊函數來顯示jquery中的點擊函數上的下一個數組項,但它沒有工作。請指點:)點擊顯示下一個數組項目
var array = [one, two, three, four, five];
$('#countButton').click(function(){
for(var i = 0; i < array.length; i++){
$('#displayCount').html(array[i++]);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<input type="button" value="Count" id="countButton" />
<p>The button was pressed <span id="displayCount">0</span> times.</p>
不循環。將您的計數器存儲在單擊事件之外並在設置html後增加它 – Sysix