-1

基本上我有这个 JS 脚本,当单击它时,它会显示更多文本。问题是,它所在的 div 与所有文本都在其中时一样大。我希望 div 仅与文本预览一样大,然后当您单击 + 按钮时,div 会扩展为与所有文本一样大。

以下是未展开时的样子:http: //puu.sh/FZj6 当它展开时:http: //puu.sh/FZjD

如您所见,div 大小始终保持不变。

JS

function hx(elmnt){document.getElementById(elmnt).style.visibility="hidden";}
function sx(elmnt){document.getElementById(elmnt).style.visibility="visible";}

HTML

       This is the text that is automatically there. When you click the + to the left, the rest of the text appears. (<a onClick="sx('more')" style="cursor:pointer;" title="Show more">+</a>)

       <div id="more" style="visibility:hidden;">
   <p>(<a onClick="hx('more')" style="cursor:pointer;" title="Show less">-</a>)<br /><br>
       This is the text that appears when the + is clicked. The - above removes this text. When the minus is clicked, the div should restore to original size.

任何帮助,将不胜感激!谢谢。

4

2 回答 2

1

也可以使用display而不是visibility删除空白空间;

function hx(elmnt){document.getElementById(elmnt).style.display = "none";}
function sx(elmnt){document.getElementById(elmnt).style.display = "block";}
于 2012-07-05T05:51:29.113 回答
1

height:auto如果您使用的是固定的,则为您显示内容的主 div制作height

于 2012-07-05T05:53:52.863 回答