<?xml version="1.0" encoding="UTF-8"?>
<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);
// <
exp = /</g;
newTxt = newTxt.replace(exp,"<");
// >
exp = />/g;
newTxt = newTxt.replace(exp,">");
// &
exp = /&/g;
newTxt = newTxt.replace(exp,"&");
elem.innerHTML = newTxt;
},false);
function reconstructTag(_tag)
{
return _tag.replace(//g, '');
}
//]]>
</constructor>
</implementation>
</binding>
</bindings>
var newTxt = chars.join('');
括号里面因该有(& # 8203;),上面没有显示出来。
PHP做的后台,smarty做的模板。在显示的时候做了一个回车的处理,用的smarty的replace方法。如果不做回车处理,在DIV中不会显示回车。
style="word-wrap:break-word;" 这个属性是在IE中自动换行。
只有在FF浏览器中才会触发 class="wordwrap" 这个样式。
wordwrap.xml中的源码部分是借鉴国外的一个博客内容,自己增加了< > &符合的处理。暂时只适用于经过PHP函数htmlspecialchars处理过的数据,其他语言需要稍作修改。
这是wordwrap.xml原文的地址,有兴趣的可以参考一下
http://blog.stchur.com/2007/02/22/emulating-css-word-wrap-for-mozillafirefox/
<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);
// <
exp = /</g;
newTxt = newTxt.replace(exp,"<");
// >
exp = />/g;
newTxt = newTxt.replace(exp,">");
// &
exp = /&/g;
newTxt = newTxt.replace(exp,"&");
elem.innerHTML = newTxt;
},false);
function reconstructTag(_tag)
{
return _tag.replace(//g, '');
}
//]]>
</constructor>
</implementation>
</binding>
</bindings>
.wordwrap {
width:750px;
word-wrap:break-word;
-moz-binding: url('/css/syaken/wordwrap.xml#wordwrap');//css/syaken/换成你放XML的地址
overflow: hidden;
}
width:750px;
word-wrap:break-word;
-moz-binding: url('/css/syaken/wordwrap.xml#wordwrap');//css/syaken/换成你放XML的地址
overflow: hidden;
}
<div class="wordwrap" style="word-wrap:break-word;">
{$coupon_comment|replace:"\r\n":"<br>"}
</div>
{$coupon_comment|replace:"\r\n":"<br>"}
</div>
var newTxt = chars.join('');
括号里面因该有(& # 8203;),上面没有显示出来。
PHP做的后台,smarty做的模板。在显示的时候做了一个回车的处理,用的smarty的replace方法。如果不做回车处理,在DIV中不会显示回车。
style="word-wrap:break-word;" 这个属性是在IE中自动换行。
只有在FF浏览器中才会触发 class="wordwrap" 这个样式。
wordwrap.xml中的源码部分是借鉴国外的一个博客内容,自己增加了< > &符合的处理。暂时只适用于经过PHP函数htmlspecialchars处理过的数据,其他语言需要稍作修改。
这是wordwrap.xml原文的地址,有兴趣的可以参考一下
http://blog.stchur.com/2007/02/22/emulating-css-word-wrap-for-mozillafirefox/