作者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