作者k85097ok (小茶)
看板Visual_Basic
標題[.NET] 隨機變換按鈕位置
時間Sat Dec 4 18:45:11 2010
請輸入專案類型(網站專案或者應用程式專案):
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>
</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
1F:→ MOONRAKER:何必交換位置 交換兩個按鈕的Text不就結了 12/04 20:50
2F:→ MOONRAKER:再用一個屬性或hidden input記現在哪一個按鈕是哪一個 12/04 20:51
3F:→ MOONRAKER:兩個按鈕共用一個event handler 不要寫成兩個 12/04 20:51
4F:→ MOONRAKER:裡面用sender判斷按下的是哪一個按鈕 做不同處理 12/04 20:52
5F:→ MOONRAKER:這是第一種 12/04 20:52
6F:→ MOONRAKER:或者不要把按鈕寫死 宣告一個panel 在load的時候動態 12/04 20:53
7F:→ MOONRAKER:產生兩個按鈕 依亂數決定先把哪一個插入panel 12/04 20:53
8F:→ MOONRAKER:這是第二種 當然你也可以給兩個td分別取個ID 就更簡單 12/04 20:54
9F:→ k85097ok:感謝樓上 我打算採用第一種 沒想到有這種寫法 12/05 03:25