使用text-overflow:ellipsis對溢出文本顯示省略號有兩個好處,一是不用經過程序限定字數;二是有利於SEO。須要使用對對溢出文本顯示省略號的一般是文章標題列表,這樣處理對搜索引擎更友好,由於標題實際上並未被截字,而是侷限於寬度而未被顯示而已。 一般的作法是這樣的: 1.overflow:hidden; 2.text-overflow:ellipsis; 3.-o-text-overflow:ellipsis; 4.white-space:nowrap; 5.width:100%; 其中,overflow: hidden和white-space: nowrap都是必須的不然不會顯示省略號;-o-text-overflow: ellipsis針對Opera;而寬度的設定主要是針對IE6; 該方法支持Internet Explorer, Safari, Chrome 和 Opera,但FF並不支持,不過能夠經過Jquery來實現相似的效果。 下載這個Jquery插件:jQuery ellipsis plugin 調用方法: 1.$(document).ready(function() { 2. $('.ellipsis').ellipsis(); 3.}
macro 宏控制
#macro(substring $str $length $replace) #if($str.length() > $length) $!{str.substring(0,$length)}$replace #else $str #end #end