-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

height:auto固定を使用している場合は、コンテンツを表示しているメインdivのを作成しますheight

于 2012-07-05T05:53:52.863 に答える
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 に答える