html连续英文或者数字的解决办法

本文介绍了一种在Firefox浏览器中实现自动换行的方法,并详细解释了如何通过XML绑定及CSS属性来达到这一目的。该方案特别针对经过htmlspecialchars处理的数据。
<?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 = /&​l​t​;/g;
                    newTxt = newTxt.replace(exp,"&lt;");

                    // >
                    exp = /&​g​t​;/g;
                    newTxt = newTxt.replace(exp,"&gt;");

                    // &
                    exp = /&​a​m​p​;/g;
                    newTxt = newTxt.replace(exp,"&amp;");

                    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;
}

<div class="wordwrap" style="word-wrap:break-word;">
    {$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/

转载于:https://www.cnblogs.com/zhangjingjing85621/archive/2009/07/23/1529265.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值