jquery 限制显示字数 ,多余的用...代替 IE 正常 firfox 只显示... - Web 开发 / Ajax
jquery 代码如下:
    $(function () {
	$(".t .td").each(function () {
		var maxwidth = 6;
		if ($(this).text().length > maxwidth) {
			var b = $(this).children().is("a");
			if (b) {
				$(this).children().text($(this).children().text().substring(0, maxwidth) + "...");
			} else {
				$(this).text($(this).text().substring(0, maxwidth));
				$(this).text($(this).text() + "...");
			}
		}
	});
});
为什么在 IE 下是好的,但是在 firfox 下只显示...  , 大家帮忙看看
------解决方案--------------------
------解决方案--------------------
楼主的代码应该没有问题,在FF下测试了一下,没有出现所说的问题。
JScript code
<script src="jquery.js"></script>
<table class="t">
<tr>
 <td class="td">1234567890</td>
</tr>
</table>
<script>
$(function () {
$(".t .td").each(function () {
var maxwidth = 6;
if ($(this).text().length > maxwidth) {
var b = $(this).children().is("a");
if (b) {
$(this).children().text($(this).children().text().substring(0, maxwidth) + "...");
} else {
$(this).text($(this).text().substring(0, maxwidth));
$(this).text($(this).text() + "...");
}
}
});
});
</script>