0

当字符超过 320 个字符时,如何创建生物信息描述 阅读更多(点击在同一页阅读全文)。

以下是我在此页面上的生物信息描述。

<p><?php echo $curauth->description; ?></p>
4

1 回答 1

0

这是一个工作示例:http: //jsfiddle.net/S8Cxr/

HTML:

<p id="bio">I am a sahm (stay at home mom) mom of 8, passionately interested in...well..my interests! I am restoring a 100 year old farm house, homeschooling the six kids still at home, raising Nigerian Dwarf Dairy goats, and trying to change our lives and those around us by the decisions and choices we make daily. I love reading, spinning fiber, sewing, cooking, writing, painting, crafting, antiquing...and just about anything shiny can grab my interest for a bit..Well maybe I am not that bad.</p>​

JavaScript:

$(document).ready(function() {
    var bio = $('#bio');
    var text = bio.text();

    if (text.length > 320) {
        bio.html(text.slice(0, 320) + '<span class="more">... (<a class="expand" href="#">more</a>)</span><span class="hidden">' + text.slice(320) + '</span>');

        $('.expand').on('click', function(event) {
            $(event.target)
                .closest('p')
                .find('.hidden')
                    .removeClass('hidden')
                    .end()            
                .find('.more')
                    .remove();
        });
    }    
});​
于 2012-12-05T01:25:00.903 回答