不显示所有行信息(仅当我按“查看”时)

时间:2013-01-06 18:00:31

标签: html rows tabular

我有一个奇怪的问题!   我制作了一个简单的创建/删除备注表单和一个脚本来查询它们。但是如果有人插入一个100KM的音符并且表格显示全部,那么它就不会很漂亮。

我请你建议我一个脚本,只显示行的一些内容,其余的按下“查看全部”的内容。  例如:

enter image description here

2 个答案:

答案 0 :(得分:1)

您需要考虑截断内容字符串,这里有大量基于JavaScript和PHP的解决方案的答案:

JavaScript: smart way to shorten long strings with javascript
PHP: Shorten string with a "..." body

因此,您要显示截断的字符串,然后在完整视图中使用原始字符串。

根据示例中表格的设置方式,您也可以尝试使用CSS截断并添加elipses。

CSS: http://css-tricks.com/snippets/css/truncate-string-with-ellipsis/

答案 1 :(得分:1)

嗯,我想你想要这样的事情:
Live jsfiddle

JS

$(function()
{
    var maxShow = 50;
   $( ".holder" ).each(function() 
   {
       var txt = $(this).text();
       txt = txt.substr(0,maxShow)+' ...';
       $(this).prev().prev().text(txt);
   });
  $(".show").click(function()
  {
      var txt = $(this).next('span').text();
      $(this).parent().text(txt);
  });
});

<强> HTML

<div class='txt'><span class='summery'></span><a href="#" class="show">view</a><span class='holder'> 0 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>
<div class='txt'><span class='summery'></span><a href="#" class="show">view</a><span class='holder'> 1 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>
<div class='txt'><span class='summery'></span><a href="#" class="show">view</a><span class='holder'> 2 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>

<强> CSS

.holder
{
  display:none;
}