我有一个我正在制作的掷硬币程序的循环。问题是它似乎很早就退出了。看一看。
$(function() {
    $('#rollDice').click(function() {
        var e = document.getElementById("diceSides");
        var diceSides = e.options[e.selectedIndex].text;
        var diceRolls = document.getElementById('rollCount').value;
        if (diceRolls.match(/^[\d]*$/ )) {      
            if (diceRolls == "")  {
                alert ("Please fill out all forms then try again.");
            } else {
                $('#diceRollContainer').slideDown('slow');
                for (i=0;i<diceRolls;i++) {
                    var randNum = Math.floor(Math.random()*diceSides)+1;
                    var rolls = ("You rolled a " + diceSides + " sided die " + diceRolls + " times, and got the numbers ");
                    rollMinOne = rolls - 1;
                    if (i == rollMinOne) {
                        var rolls = (rolls + randNum + ".");
                    }
                    var rolls = (rolls + randNum + ", ");
                }
                alert (rolls);
            }
        } else {
            alert ("Make sure you only enter numbers and no spaces, then try again.");
        }
    });
});
问题是程序在 for 循环似乎完成之前警告滚动。为什么要这样做?