<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
  <asp:ListItem Value="-1" onchange="clear()">学生</asp:ListItem>
  <asp:ListItem Value="0">教师</asp:ListItem>
</asp:RadioButtonList>        
而他生成的html则是
<table id="RadioButtonList1" border="0">
  <tr>
    <td><span onchange="clear()"><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="-1" /><label for="RadioButtonList1_0">学生</label></span></td><td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="0" /><label for="RadioButtonList1_1">教师</label></td>
</tr>
</table>                 怎样来正确添加js onchange="clear()"事件
谢谢

解决方案 »

  1.   

    后台Page_OnLoad()方法中添加
    RadioButtonList1.Attributes.Add("onchange", "clear()");
      

  2.   

    <asp:RadioButtonList ID="RadioButtonList1"   runat="server" RepeatDirection="Horizontal">
      <asp:ListItem Value="-1"  onclick="javascript:clear1()" >学生</asp:ListItem>
      <asp:ListItem Value="0">教师</asp:ListItem>
    </asp:RadioButtonList>  <script type="text/javascript">
         function clear1()
         {
            alert("点击了.");
         }
     </script>
      

  3.   

    for (int ix = 0; ix < RadioButtonList1.Items.Count; ix++ )
            {
                RadioButtonList1.Items[ix].Attributes.Add("onchange", "clear();");
            }
      

  4.   

    clear好像是个关键字.要换个名字 .
      

  5.   

    然后我用
    if(document.getElementById("<%= rbl_Object.ClientID %>"+"_1").checked)
    这里是判断是否选中的
    虽然这样可以
    但不知道有没有更好的写法
      

  6.   

    其他办法也有,但并不比这个好.如:根据表格的rows来确定.