RadioButtonList 的js问题

shizheyangde 2009-01-09 10:57:28
<td align="left" >分数:<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"
>
<asp:ListItem Text="全选12分" Value="12" Selected="False"></asp:ListItem>
<asp:ListItem Text="全选9分" Value="9" Selected="False"></asp:ListItem>
<asp:ListItem Text="全选6分" Value="6" Selected="False"></asp:ListItem>
</asp:RadioButtonList>
</td>
js代码:
function SelectAll()
{
if(document.getElementById('ctl00_ContentPlaceHolder1_RadioButtonList1_0').checked==true )
{
alert('ok');
}
if(document.getElementById('ctl00_ContentPlaceHolder1_RadioButtonList1_1').checked==true)
{
alert('ok2');
}
if(document.getElementById('ctl00_ContentPlaceHolder1_RadioButtonList1_2').checked==true )
{
alert('ok3');
}
}

cs:代码
if (!IsPostBack)
{
RadioButtonList1.Attributes.Add("onclick", "SelectAll();");
}

选择“全选12分”,弹出‘ok’;
再选“全选9分”,弹出‘ok’,再弹出‘ok2’;
...
然后总是类似的弹出两次,为什么?
...全文
174 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ycguo 2009-02-12
  • 打赏
  • 举报
回复
支持4楼

foreach (ListItem li in this.RadioButtonList1.Items)
{
li.Attributes.Add("onclick", "SelectAll();");
}
zhou21cnzx 2009-02-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 phper2008 的回复:]
引用 4 楼 Jinglecat 的回复:
你看 html 代码就知道原因了,

加在每个 Item 上,不要直接加在 RadioList 上

if (!IsPostBack)
{
foreach(ListItem item in RadioButtonList1.Items) {
item.Attributes.Add("onclick", "SelectAll();");
}


支持!
[/Quote]

支持
phper2008 2009-01-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Jinglecat 的回复:]
你看 html 代码就知道原因了,

加在每个 Item 上,不要直接加在 RadioList 上

if (!IsPostBack)
{
foreach(ListItem item in RadioButtonList1.Items) {
item.Attributes.Add("onclick", "SelectAll();");
}

[/Quote]
支持!
Jinglecat 2009-01-09
  • 打赏
  • 举报
回复
你看 html 代码就知道原因了,

加在每个 Item 上,不要直接加在 RadioList 上

if (!IsPostBack)
{
foreach(ListItem item in RadioButtonList1.Items) {
item.Attributes.Add("onclick", "SelectAll();");
}
zhuanshen712 2009-01-09
  • 打赏
  • 举报
回复
看看页面源码,为什么总是要弹出ok
koukoujiayi 2009-01-09
  • 打赏
  • 举报
回复
觉得代码好象没问题!!
萤火架构 2009-01-09
  • 打赏
  • 举报
回复
RadioButtonList1.Attributes.Add("onclick", "SelectAll();");
onclick恐怕不妥
换成onselectedchanged(具体可能不是这个名字)

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧