css 與js 強行換行代碼

來源:互聯網
上載者:User
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>

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.