我有一个使用以下类的div:
div.textStatement
{
height: 70px;
overflow: hidden;
}
当用户点击链接(“显示更多”)时,div会展开以显示更多文本,并且“溢出”应设置为“滚动”,以便用户可以阅读所有文本,如果有比div的高度更多的文字会显示出来。但是,对div的'overflow'属性的引用将返回'undefined',因此我无法将其设置为'scroll'。知道为什么对div的溢出的引用回来'未定义'?我认为这样可以解决问题(并使滚动条显示出来)。
这是div:
<asp:Panel ID="textStatement" class="textStatement" runat="server"></asp:Panel>
<label id="candidateStatementShowMoreLess" class="MoreLess" onclick="ShowMoreLess(this)">Show More</label>
这是javascript(使用jQuery):
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;
}
}
}
答案 0 :(得分:4)
section.attr("overflow", "scroll");
不正确。它必须是
section.css("overflow", "scroll");