Javascript显示用户输入

时间:2013-10-30 18:30:55

标签: javascript

用户按下输入数字按钮后,如何在文本框中显示用户输入的数字。无法上班。

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>

2 个答案:

答案 0 :(得分: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;
}

FIDDLE

答案 1 :(得分:0)

尝试:

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

为您提供逗号分隔的数字列表。如果需要,您可以将其他分隔符传递给.join