2011-09-22 141 views
0

我用下面的類一個div:CSS設置溢出滾動不工作

div.textStatement 
{ 
    height: 70px; 
    overflow: hidden; 
} 

當用戶點擊一個鏈接(「查看更多」),股利展開,顯示更多的文字和「溢出「應該設置爲」滾動「,以便用戶可以閱讀所有的文本,如果有更多的文本比div的高度將顯示。但是,對div的'overflow'屬性的引用會返回'undefined',因此我無法將其設置爲'滾動'。任何想法爲什麼ref的div溢出回來'未定義'?我認爲這將解決問題(並使滾動條出現)。

這裏的DIV:

<asp:Panel ID="textStatement" class="textStatement" runat="server"></asp:Panel> 
<label id="candidateStatementShowMoreLess" class="MoreLess" onclick="ShowMoreLess(this)">Show More</label> 

這裏的(使用jQuery)的JavaScript:

var IsStatementExpanded = false; 
var IsDescriptionExpanded = false; 

function ShowMoreLess(moreLessLink) 
{ 
    var section = $(moreLessLink).prev("div"); 
    var sectionId = $(section).attr("id"); 
    var collapsedHeight = 70; 
    var expandedHeight = 300; 

    if (section.height() == collapsedHeight) 
    { 
     section.animate({ height: expandedHeight }, 500, 
      function() 
      { 
       $(moreLessLink).html("Show Less"); 

       // ***** This should be setting the overflow to scroll on the div, but isn't, as "attr" is coming back undefined. ***** 
       section.attr("overflow", "scroll"); 
      }); 

     if (sectionId == "textStatement") 
     { 
      IsStatementExpanded = true; 
     } 
     else if (sectionId == "textDescription") 
     { 
      IsDescriptionExpanded = true; 
     } 
    } 
    else 
    { 
     section.animate({ height: collapsedHeight }, 500, 
      function() 
      { 
       $(moreLessLink).html("Show More"); 

       // ***** This could have the same problem as above, but when the user collapses the div. ***** 
       section.attr("overflow", "hidden"); 
      }); 

     if (sectionId == "textStatement") 
     { 
      IsStatementExpanded = false; 
     } 
     else if (sectionId == "textDescription") 
     { 
      IsDescriptionExpanded = false; 
     } 
    } 
} 

回答

4
section.attr("overflow", "scroll"); 

不正確。它需要是

section.css("overflow", "scroll"); 
+0

太棒了!謝謝!!! – birdus

+0

不客氣。樂意效勞 :) –