3

我有一个带有文本“点击我”的 div

和带有有限视图文本选项的“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;
 }

如果可以,那就太好了。

4

1 回答 1

3

这可以使用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>

于 2013-06-28T18:44:15.817 回答