function tobreakword(intlen, id){
var obj=document.getelementbyid(id);
var strcontent=obj.innerhtml;
var strtemp="";
while(strcontent.length>intlen){
strtemp+=strcontent.substr(0,intlen)+"<br>";
strcontent=strcontent.substr(intlen,strcontent.length); }
strtemp+= strcontent;obj.innerhtml=strtemp;
}
css强制换行
强制换行:word-break:break-all;white-space:normal;word-wrap:break-word; (table最好加上table-layout:fixed;)
js代码
<script>
function tobreakword(intlen){
var obj=document.getelementbyid("ff");
var strcontent=obj.innerhtml;
var strtemp="";
while(strcontent.length>intlen){
strtemp+=strcontent.substr(0,intlen)+"
";
strcontent=strcontent.substr(intlen,strcontent.length);
}
strtemp+="
"+strcontent;
obj.innerhtml=strtemp;
}
if(document.getelementbyid && !document.all) tobreakword(37)
</script>