加一個css屬性即可
style = "word-wrap:break-word;"
js代碼:
"render": function (data, type, full, meta) {
return '<p style="word-wrap:break-word;">' + data + '</p>'
}
但有時word-wrap會失效,原因如下:
1.word-wrap
對行內元素是沒有效果的
2.一般情況下,元素擁有默認的white-space:normal(自動換行,不換行是white-space:nowrap),可能是元素中設置的white-space是norwrap導致,無法換行。所以需要設置:
white-space:normal;
word-break:break-all;
在 td 里面 加上 style="word-wrap:break-word;" 自動換行就好了,如果不想換行,可以將超出內容設為隱藏,
overflow:hidden;
white-space:nowrap;
(1)超過寬度和高度文字會自動隱藏
<div style="width:100px;height:25px;overflow-x:hidden;overflow-y:hidden;">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
(2)設置了td的寬度超過長度自動換行
<td>
<div style="width:100px;word-wrap:break-word;" >cvcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</div>
</td>