日期:2014-05-16  浏览次数:20334 次

通过jquery控制CheckBoxList中的选项
HTML code

<div>
        <asp:CheckBoxList ID="chktest" runat="server">
            <asp:ListItem Value="1">控制TextBox1显示/隐藏</asp:ListItem>
            <asp:ListItem Value="2">控制TextBox2显示/隐藏</asp:ListItem>
        </asp:CheckBoxList>
        <asp:TextBox ID="textBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="textBox2" runat="server"></asp:TextBox>
    </div>



------解决方案--------------------
JScript code

<script language="javascript" type="text/javascript">
  $(function() {

  $("#chktest input[type=checkbox]").eq(0).click(function() {
  if ($(this).attr("checked")) {
  $("#textBox1").show();
  }
  else {
  $("#textBox1").hide();
  }
  });
  $("#chktest input[type=checkbox]").eq(1).click(function() {
  if ($(this).attr("checked")) {
  $("#textBox2").show();
  }
  else {
  $("#textBox2").hide();
  }

  });

  });
  </script>