我在div中显示一些内容时遇到问题。
我有一些文字考虑了必须在div中显示的10行内容。
我想以一种方式设计,使div最初仅显示2行内容,并具有一个链接“ Read Complete”。 &当我单击该链接时,必须显示整个内容,并且链接必须更改为“隐藏”。 &如果我再次单击“隐藏”链接,则必须再次仅显示两行内容。

请帮助我这个问题。

更新:当内容为两行@内容结尾时,它必须显示3个点(...)

最佳答案

我希望这能帮到您

<div id="mydiv">
Please read the documentation.
For updates please follow our blog, tweets or become a fan.
    <span><a href="#" id="more" onclick="full_view(this.id)">more</a></span>
<span style="display:none;" id="disMore"><p>Please read the documentation.
For updates please follow our blog, tweets or become a fan.Please read the documentation.
For updates please follow our blog, tweets or become a fan.Please read the documentation.
For updates please follow our blog, tweets or become a fan.</p></span>
<span><a href="#" id="hide" onclick="half_view(this.id)" style="display:none;">hide</a></span>
</div>


Javascript:

function full_view(e) {
document.getElementById('disMore').style.display = "block";
document.getElementById('more').style.display = "none";
document.getElementById('hide').style.display = "block";
}
function half_view(e) {
document.getElementById('disMore').style.display = "none";
document.getElementById('more').style.display = "block";
document.getElementById('hide').style.display = "none";
}

关于javascript - 仅显示div内容,最多两行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8710555/

10-09 08:09
查看更多