gpt4 book ai didi

jquery - 单击以展开文本

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

我有一个带有文本“Click Me”的 div

和带有有限 View 文本选项的“P”标签。 jquery 有什么方法可以单击“单击我”并展开文本。然后再次单击我隐藏。对不起,我不擅长 jQuery。没有找到方法我成功了。

查看现场演示 js Fiddle:http://jsfiddle.net/saifrahu28/7wKyj/

**HTML**
<div>Click me</div>

<p>
It is a long established fact that a reader
will be distracted by the readable content of a
page when looking at its layout. The point of using Lorem Ipsum
is that it has a more-or-less normal distribution of letters,
as opposed to using 'Content here, content here',
making it look like readable English. Many desktop publishing
<p>

CSS

p{
overflow: hidden;
text-overflow: ellipsis;
display: block;
white-space: nowrap;
width:100px;
}

如果可以那就太好了。

最佳答案

这可以使用 toggleClass(许多选项之一)来完成

$("element").toggleClass("className");

$(function(){
$("#clickMe").click(function(){
$("#para").toggleClass("myClass");
})
});
p{
text-overflow: ellipsis;
display: block;
white-space: nowrap;
width:100px;
}

.myClass
{
overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="clickMe">Click me</div>

<p id="para" class="myClass">
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing
<p>

关于jquery - 单击以展开文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17371421/

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