1

用户按下输入数字按钮后,如何在文本框中显示用户输入的数字。不能让它工作。

function userNumbers()
{
    var usersNumbers = new Array(5)
    for(var count = 0; count <=5; count++){
        usersNumbers[count]=window.prompt("Enter your number "+(count+1)+": " );
    }
    document.lotto.usersNumbers.value = output;
}

 <table width=100% border=0>
 <tr>
 <td>
 <p><input type=button value="Enter your numbers" onClick="userNumbers()"></p>
 Your Numbers: 
 <textarea name="usersNumbers" rows=1 cols=20></textarea>
 </td>
 </tr>
4

2 回答 2

1

你可以试试这个:

<textarea name="usersNumbers" id="textarea" rows=1 cols=20></textarea>

 

function userNumbers() {
    var usersNumbers = new Array(5);
    for (var count = 0; count <= 5; count++) {
        usersNumbers[count] = window.prompt("Enter your number " + (count + 1) + ": ");
    }
    document.getElementById("textarea").value = usersNumbers;

    // if using form
    //document.lotto.usersNumbers.value = usersNumbers;
}

小提琴

于 2013-10-30T18:42:39.483 回答
0

尝试:

document.lotto.usersNumbers.value = userNumbers.join();

给你一个逗号分隔的号码列表。如果需要,您可以传递不同的分隔符.join

于 2013-10-30T18:34:39.813 回答