第一种方法:
JavaScript代码
<script>function toBreakWord(intLen){var obj=document.getElementById("ff");var strContent=obj.innerHTML;var strTemp="";while(strContent.length>intLen){strTemp+=strContent.substr(0,intLen)+"<br>";strContent=strContent.substr(intLen,strContent.length);}strTemp+="<br>"+strContent;obj.innerHTML=strTemp;}if(document.getElementById && !document.all) toBreakWord(37)</script>
HTML代码
<div id="ff" style="border:1px solid red;width:300px;word-wrap:break-word;"> DIV+CSS模板、后台模板、图片图标下载,CSS代码实例、CSS导航菜单、CSS图表 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <h3><a href="http://www.3zha.com" style="color:#000;">www.xuyuanqiang.cn</a></h3></div>
第二种方法:
.wordwrap
wordwrap.xml的内容如下
<?xml version = "1.0"?>
<bindings xmlns = "http://www.mozilla.org/xbl" xmlns:html = "http://www.w3.org/1999/xhtml">
<binding id = "wordwrap" applyauthorstyles = "false">
<implementation>
<constructor>
// <![CDATA[
var elem = this;
elem.addEventListener(‘overflow’,
function()
{
var exp = / <​\/*[​_\s="’\w]+>/g;
var txt = elem.innerHTML;
var chars = txt.split(”);
var newTxt = chars.join(‘​’);
newTxt = newTxt.replace(exp, reconstructTag);
elem.innerHTML = newTxt;
},false);
function reconstructTag(_tag)
{
return _tag.replace(/​/g, ”);
}
//]]>
</constructor>
</implementation>
</binding>
</bindings>
<!– Web2 –>
用法直接class="wordwrap"即可
评论前必须登录!
注册