<div id="content" style="height:auto;">
        <div id="xleft">
            <div id="xtop">
                <div style="background: url(images/xwxq.jpg) no-repeat 330px 6px; height: 30px;">
                </div>
            </div>
            <div id="New" style="background-color:#FFF; width:666px; margin-left:8px; padding-top:37px; height:620px;">
                <asp:Repeater ID="Repeater2" runat="server">
                    <ItemTemplate>
                        <div style="width: 522px; line-height: 24px; text-indent: 24px; color: #026CA8; text-align: left;
                            margin-left: 50px;">
                            <p style="color: #026CA8; font-weight: bold; text-align: center; border-bottom: 1px dotted #026CA8;
                                padding-bottom: 4px; margin-bottom: 4px; font-size: 14px;">
                                <%# Eval("NTMT_NewName")%>
                            </p>
                            <p style="color: #838383; text-align: center; margin-bottom: 7px;">
                                发布人:<%# Eval("NTMT_ManagerName")%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;发布时间:<%# Eval("NTMT_NewDate")%></p>
                            <p><%# Eval("NTMT_NewMain")%></p>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
            </div>
        </div> <script language="javascript" type="text/javascript">
        var New=document.getElementById("New");
        if(New.offsetHeight>=620)
        {
           
          New.style.height="auto";
        }
        else
        {
              New.style.height="620px";
            //New.style="background-color:#FFF; width:666px; margin-left:8px; padding-top:37px; height:620px;"
        }
   </script>以我的想法这样他应该在div的高度大于620的情况下,将其调整为auto,反之则默认为620px;,可是这样写不行,大于620px的时候,他会变为auto,小于他却不是620px!
谁有更好的办法??
能达到,控制文体的高度,文本的内容一定要全部显示,文字少的时候高度为一个默认值!

解决方案 »

  1.   

    这是我的测试代码,LZ可以试试
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title></head><body>
    <div id="New" style="background-color:#cccccc">内容</div>
    <script language="javascript" type="text/javascript">
            var New=document.getElementById("New");
            if(New.offsetHeight>=620)
            {
              New.style.height="auto";
            }
            else
            {
                  New.style.height="620px";
                //New.style="background-color:#FFF; width:666px; margin-left:8px; padding-top:37px; height:620px;"
            }
       </script></body></html>