【问题标题】:Using html in jquery expand collapse在jquery中使用html展开折叠
【发布时间】:2013-07-17 07:49:38
【问题描述】:

我在我的网站上使用以下 jquery 和 html 代码展开折叠:

<script>
$(document).ready(function () {
    $('.fulltext').hide();

    $('.blog-item .readmore').click(function (event) {
        event.preventDefault();
        $(this).parent().find('.fulltext').slideToggle('slow');
        $(this).text($(this).text() == 'Close Deals' ? 'More Deals' : 'Close Deals');
    });
});
</script>

HTML:

<div class="blog-item">
        <p class='fulltext'>Read more text will be here.</p>
    <a class="readmore" href="#">Read more..</a>
</div>

实际上我想在隐藏文本中使用表格,现在是:&lt;p class='fulltext'&gt;Read more text will be here.&lt;/p&gt;

但是当我在全文中使用表格时,它会停止工作。请任何建议。

【问题讨论】:

  • 你应该使用prev()而不是parent().find('.fulltext');

标签: jquery expand collapse


【解决方案1】:

&lt;p class="fulltext"&gt; 更改为&lt;div class="fulltext"&gt;,它应该可以正常工作。 &lt;p&gt; 中不能有其他块元素。

【讨论】:

    【解决方案2】:

    &lt;div&gt; 元素旨在描述数据容器,而&lt;p&gt; 元素旨在描述一段内容。要使用内部表格,请使用div 标签。

    Fiddle

    【讨论】:

      猜你喜欢
      • 2011-03-01
      • 2015-02-15
      • 2017-02-12
      • 1970-01-01
      • 2011-03-18
      • 2013-05-31
      • 2012-05-15
      • 1970-01-01
      • 2016-04-18
      相关资源
      最近更新 更多