<a>标签的title属性,可以提供提示性的语言;当鼠标放在<a>标签上时,就会显示出内容来;
但是当要显示一个内容比较长时,title属性中的内容不会换行,会让页面不够漂亮;
解决方法是可以在title内容中加入" "内容,来控制换行;
以下是我实现的方法:
truncate(h(unit.memo), 10) :自带方法,用于当内容字节长度超过10个字节时,只截取10个字符,而后的内容用"......."代替;
<a href="javascript:void(0)" title="<%=shortdesc(h(unit.memo),30)%>"><%=truncate(h(unit.memo), 10) %></a>
def shortdesc(desc,maxlength)
return "" if desc.blank?
i = 0
str = ""
chars = desc.chars
chars.each do |e|
str << e
if(++i / maxlength==0 )
str += " "
end
end
return str
end
表格中的<td>也可设置tilte属性!