单击以展开文本

时间:2013-06-28 18:35:34

标签: jquery html css

我有一个带文字的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;
 }

如果可以,那将是伟大的。

1 个答案:

答案 0 :(得分:1)

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