Asp.Net中关于td的内容超出后自动隐藏问题

1. 页面加载后执行js修改样式:

<script type="text/javascript">
      function hiddenTdTextWhenOverflow() 
        {
            var tempTable = document.getElementById("G_ctl00xBodyContentPlaceHolderxctrlGlanceReportxuwgGlanceReport");
            var currentTBody = tempTable.getElementsByTagName("tbody")[0];
            var currentTBodyTrArr = currentTBody.childNodes;
            for (i = 0; i < currentTBodyTrArr.length; i++) {
                var currentTrTdArr = currentTBodyTrArr[i].childNodes;
                for (j = 0; j < currentTrTdArr.length; j++) {
                    currentTrTdArr[j].style.overflow = "hidden";
                }
            }
        }

        window.onload = hiddenTdTextWhenOverflow;
    </script>




2. 点击按钮执行完后台代码后执行js

在aspx文件中定义js函数:

<script type="text/javascript">
          function hiddenTdTextWhenOverflow() {
            var tempTable = document.getElementById("G_ctl00xBodyContentPlaceHolderxUltraWebGrid1");
            var currentTBody = tempTable.getElementsByTagName("tbody")[0];
            var currentTBodyTrArr = currentTBody.childNodes;
            for (i = 0; i < currentTBodyTrArr.length; i++) {
                var currentTrTdArr = currentTBodyTrArr[i].childNodes;
                for (j = 0; j < currentTrTdArr.length; j++) {
                    currentTrTdArr[j].style.overflow = "hidden";
                }
            }
        }

    </script>



后台逻辑处理完局部页面加载前执行函数,在.aspx.cs类型文件中调用:

protected void btnViewReport_Click(object sender, EventArgs e)
    {
        try
        {
            //此次为后台处理逻辑代码

            ClientScript.RegisterStartupScript(this.GetType(), "hiddenTdTextWhenOverflow", @"<script type='text/javascript'>hiddenTdTextWhenOverflow();</script>");
        }
        catch (Exception ex)
        {
            divError.Visible = true;
            lblError.Text = ex.Message;
        }
    }

你可能感兴趣的:(asp.net)