【问题标题】:Increased height of panel in div clickdiv点击中面板的高度增加
【发布时间】:2014-04-24 03:39:13
【问题描述】:

我想在 div 点击时增加面板的高度。

<script language="javascript" type="text/javascript">
function getheight(this)
{
    document.getElementById('Panel1').style.height="200px";
}
</script>
<div id="flip" onclick="getheight(this)"><div>
<div>
    <asp:Panel ID="Panel1" runat="server" BorderStyle="Dotted" Height="50px" Width="125px" ScrollBars="Horizontal">
        </asp:Panel>

</div>

【问题讨论】:

    标签: javascript asp.net vb.net


    【解决方案1】:

    这是一个服务器端控件,因此您不会找到 ID ='Panel1' 的元素。

    如果你查看这个页面生成的html的源代码你会发现真实的ID在里面使用它

    document.getElementById 函数

    您可以使用 document.getElementById('');自动插入

    脚本中的正确 ID

    【讨论】:

      【解决方案2】:

      试试这个..

      <script language="javascript" type="text/javascript">
      function getheight(this)
      {
       document.getElementById('Panel1').setAttribute("style", "height:200px;");
      }
      </script>
      

      【讨论】:

        【解决方案3】:

        由于这是一个服务器端控件,您需要设置 ClientIDMode = "Static" 以防止 .NET 分配生成的控件。

        <script language="javascript" type="text/javascript">
        function getheight(this)
        {
            document.getElementById('Panel1').style.height="200px";
        }
        </script>
        <div id="flip" onclick="getheight(this)">
            <asp:Panel ID="Panel1" runat="server" BorderStyle="Dotted" 
               Height="50px" Width="125px" ScrollBars="Horizontal" ClientIDMode="Static" />
        </div>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-11-02
          • 2010-12-04
          • 1970-01-01
          • 2015-04-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-10-24
          相关资源
          最近更新 更多