日期:2014-05-17  浏览次数:20501 次

如何实现点击linkbutton后显示DIV,再点击关闭DIV,或者让DIV里面的label清空
代码如下,效果是点击按钮后之前的label信息还在,div也没影藏
客户端:
  <script type="text/javascript">
  function fun() {
  if (document.getElementById("show").style.display == "block") {
  document.getElementById("show").style.display = "none";

  }
  else {
  document.getElementById("show").style.display = "block";
  }
  }
  </script>
  <td class="usertablerow1" width="120px">
  出勤:</td>
  <td class="usertablerow3">
  <asp:TextBox ID="txt_duty" runat="server" Width="250px"></asp:TextBox>
  <asp:LinkButton ID="lbt_check" runat="server" OnClientClick="fun()" OnClick="lbt_CheckInData" Text="点击显示考勤信息"></asp:LinkButton>
  <div id='show' style=" text-align:left; border:solid 1px #fff;background-color:#ddd; width:250px;" >
  <asp:Label ID="lab_checkin" runat="server" Text=""></asp:Label>
  </div>
  </td>
服务器端:
 protected void lbt_CheckInData(object sender, EventArgs e)
  {
  CheckInBLL bll = new CheckInBLL();
  DataTable dt = new DataTable();
  if (UserSelect1.SelectUsers.Count > 0)
  {
  int peopleid = UserSelect1.SelectUsers[0].ID;
  dt = bll.GetCheckInByPeople(peopleid);
  if (dt.Rows.Count > 0)
  {
  for (int i = 0; i < dt.Rows.Count; i++)
  {
  lab_checkin.Text += "有" + dt.Rows[i][0].ToString() + "记录" + dt.Rows[i][1].ToString() + "条 ";
  }
  }
  else
  {
  lab_checkin.Text = "该用户无考勤记录";
  }
  }
  else
  {
  lab_checkin.Text = "请先选择用户";
  }
   
  }


------解决方案--------------------
去掉所有js脚本,然后给div加个runat="server",后台用

if(show.Attributes.CssStyle["display"]=="block")
show.Attributes.CssStyle["display"]="none";
else
show.Attributes.CssStyle["display"]="block";
------解决方案--------------------
探讨

去掉所有js脚本,然后给div加个runat="server",后台用

if(show.Attributes.CssStyle["display"]=="block")
show.Attributes.CssStyle["display"]="none";
else
show.Attributes.CssStyle["display"]="block";