我看到了这个演示http://viralpatel.net/blogs/demo/jquery/show-more-link-shortened-content/并尝试实现它;如何将限制设置为 10 个字母?
<script type="text/javascript">
document.write(str.substring(0, 29) +
"<a href='javascript:show('test');'>show/hide</a>");
document.write("<style type='text/css'>.hidden{display:none}<\/style>");
function show(area) {
var obj = document.getElementById(area)
obj.style.display = (obj.style.display == 'inline') ? 'none' : 'inline'
}
</script>
<p><strong>This is the result, just test it yourself:</strong></p>
Some text has been hidden. <a href="javascript:show('test');">show/hide</a>
<span class="hidden" id="test">
Yes, this was hidden.<br>bladiebla bladiebladiebla was also hidden.
</span>