さらに多くのコードと新しい情報が含まれるように編集されました。Javascript配列がうまくいきませんか?
<asp:Table ID="Table1" runat="server" BorderWidth="2px" CellSpacing="2" GridLines="Both" Width="465px">
<asp:TableRow ID="labelRow0" runat="server">
<asp:TableCell runat="server">Name</asp:TableCell>
<asp:TableCell runat="server">Address</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="inputRow0" runat="server">
<asp:TableCell ID="inputName" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></asp:TableCell>
<asp:TableCell ID="inputAddress" runat="server">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="labelRow1" runat="server">
<asp:TableCell runat="server">Favourite Colour</asp:TableCell>
<asp:TableCell runat="server">Favourite Number</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="inputRow1" runat="server">
<asp:TableCell ID="inputColour" runat="server">
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></asp:TableCell>
<asp:TableCell ID="inputNumber" runat="server">
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button ID="buttonScramble" runat="server" Text="Scramble Info" onClientClick="return buttonScramble()" />
</div>
<script>
function buttonScramble() {
var name = document.getElementById("TextBox1").value;
var address = document.getElementById("TextBox2").value;
var colour = document.getElementById("TextBox3").value;
var number = document.getElementById("TextBox4").value;
alert(name, address, colour, number);
var arr = [name, address, colour, number];
alert(arr[0]);
//alert(arr[0], arr[1], arr[2], arr[3]);
arr.shuffle(arr);
alert(arr[0], arr[1], arr[2], arr[3]);
document.getElementById("TextBox1").value = arr[0];
document.getElementById("TextBox2").value = arr[1];
document.getElementById("TextBox3").value = arr[2];
document.getElementById("TextBox4").value = arr[3];
}
"alert(arr [0]);"コード行は決して引き起こされません。名前、アドレスなどの変数の値をチェックしたら、それらは正しく割り当てられていません。アレイが正しく割り当てられていない理由を説明します。
'のdocument.getElementById( "TextBox1テキストボックス")は、' 'のdocument.getElementById( "TextBox1テキストボックス")、その後存在しない場合は[値]は実行されません、エラーや警告を作成します。 – Michael
TextBoxのすべては確かですか? IDはありますか? – Michael
try catch内でこのブロックをラップして、エラーを参照してください... –