jQuery擷取自動截取過長的常值內容,顯示成省略符號

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   使用   sp   div   

table中如果td的內容過多,則會把td撐的很寬, 顯得不美觀.

如果能讓td既美觀.也能看到完整的效果..

 

我們則需要,在產生td之前,給指定樣式..

這裡採用jQuery來實現.

//頁面載入之後,設定.樣式.  jQuery(function(){       //使用id選取器;例如:tab對象->tr->td對象.      $("#high_light tr td").each(function(i){           //擷取td當前對象的文本,如果長度大於25;           if($(this).text().length>25){                  //給td設定title屬性,並且設定td的完整值.給title屬性.      $(this).attr("title",$(this).text());                  //擷取td的值,進行截取。賦值給text變數儲存.      var text=$(this).text().substring(0,25)+"...";                  //重新為td賦值;                  $(this).text(text);           }        });  });  

 

 

 

<html>        <head>           <title>測試<title>       </head>               <table id="high_light ">                    <tr>                           <td>  這是很長的一段常值內容,測試是否能正常截取.這是很長的一段常值內容,測試是否能正常截取.這是很長的一段常值內容,測試是否能正常截取.這是很長的一段常值內容,測試是否能正常截取.                          </td>                    </tr>        </table>  </html>  


From:http://zhouhaitao.iteye.com/blog/1160694

 

jQuery擷取自動截取過長的常值內容,顯示成省略符號

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.