[.NET] 隨機變換按鈕位置

看板Visual_Basic作者 (小茶)時間15年前 (2010/12/04 18:45), 編輯推噓0(009)
留言9則, 2人參與, 最新討論串1/1
請輸入專案類型(網站專案或者應用程式專案): ASP.NET Web 應用程式 假設網站的版面為下圖 ┌──────────┐ ┌──────────┐ │          │ │          │ │          │ │          │ │          │ │          │ │ Button1  │ │ Button2  │ │          │ │          │ │          │ │          │ └──────────┘ └──────────┘ 我希望網頁在載入時能隨機交換[Button1]與[Button2]的所在位置 但實在不曉得該怎麼寫(應該是寫Script吧?) 附上一段目前版面配置的程式碼 <table style="width:100%;"> <tr> <td align="center"> <asp:Button ID="Button1" runat="server" Font-Size="80pt" Height="320px" onclick="Button1_Click" Text="Button" Width="400px" BorderStyle="Solid" BorderWidth="0px" /> </td> <td> &nbsp;</td> <td align="center"> <asp:Button ID="Button2" runat="server" Font-Size="80pt" Height="320px" onclick="Button2_Click" Text="Button" Width="400px" BorderStyle="Solid" BorderWidth="0px" /> </td> </tr> </table> 我嘗試在Button ID="Button1"的地方執行Script 可是網頁無法執行 想請教一下板友們 該怎麼寫這段Script -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.35.207.229

12/04 20:50, , 1F
何必交換位置 交換兩個按鈕的Text不就結了
12/04 20:50, 1F

12/04 20:51, , 2F
再用一個屬性或hidden input記現在哪一個按鈕是哪一個
12/04 20:51, 2F

12/04 20:51, , 3F
兩個按鈕共用一個event handler 不要寫成兩個
12/04 20:51, 3F

12/04 20:52, , 4F
裡面用sender判斷按下的是哪一個按鈕 做不同處理
12/04 20:52, 4F

12/04 20:52, , 5F
這是第一種
12/04 20:52, 5F

12/04 20:53, , 6F
或者不要把按鈕寫死 宣告一個panel 在load的時候動態
12/04 20:53, 6F

12/04 20:53, , 7F
產生兩個按鈕 依亂數決定先把哪一個插入panel
12/04 20:53, 7F

12/04 20:54, , 8F
這是第二種 當然你也可以給兩個td分別取個ID 就更簡單
12/04 20:54, 8F

12/05 03:25, , 9F
感謝樓上 我打算採用第一種 沒想到有這種寫法
12/05 03:25, 9F
文章代碼(AID): #1C-Xl1i5 (Visual_Basic)