2011-09-22 151 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

不客气。乐意效劳 :) –