我有一個寬度設置爲100%的<table>
。在<td>
裏面是一個帶有文本字符串的div,如果文本寬度溢出,我想添加一個省略號。在調整瀏覽器大小時對文本使用CSS省略號
在JavaScript中,我將<div>
的寬度設置爲<td>
的寬度,並且此工作適用於加載(或刷新),但我無法使其工作onresize
。
(不用擔心什麼,我居然在這裏做什麼,這是一個更大的桌子,我簡化了這個問題的緣故的一部分。)
任何人都可以建議我怎麼能得到文本省略號-ify onresize
?
function doThis() {
$('.divClass').css('width', $(".tdClass").css('width'));
}
.divClass {
width:0px;
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body onload="doThis()" onresize="doThis()">
<table style="width:100%">
<tr>
<td class="tdClass">
<div class="divClass">
the quick brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog the quick brown fox jumps over the lazy dog
</div>
</td>
</tr>
</table>
</body>
請看看我的回答 – brk