gpt4 book ai didi

javascript - 存储在js var中溢出的文本

转载 作者:行者123 更新时间:2023-11-28 07:16:15 25 4
gpt4 key购买 nike

我意识到这是一个有点奇怪的问题,因为它有点自相矛盾,但我希望能够隐藏不适合 div 的文本。这很容易,但是我需要获取隐藏的文本并将其存储在 js 变量中,以便我可以在单击按钮时使其可见,例如:

<html>
<body>
<div style = "height:10px;width:50px;word-wrap:break-word;overflow:hidden">
<p id = "text">Text that is too big for div</p>
</div>
</body>
</html>

JS

var overflow = /*equates to overflow of div*/
$(document).click(function(){
document.getElementById('text').innerHTML = overflow
})

类似的东西。

最佳答案

为什么不去掉点击时的 overflow: hidden 属性?

var content = document.getElementById('content'),
button = document.getElementById('unhide');

button.addEventListener('click', function(){
content.style.overflow = 'visible';
});
<button id="unhide" type="button">Unhide</button>
<div id="content" style="height:35px;width:100px;word-wrap:break-word;overflow:hidden">
<p>Text that is too big for div. Text that is too big for div.
Text that is too big for div. Text that is too big for div. </p>
</div>

关于javascript - 存储在js var中溢出的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32337388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com