Title 内容有英文箭括号显示问题

 if (value.length > 30) {
                                    var EncodeStr = EncodeString(value);
                                    dsg = "<div title=\"" + EncodeStr + "\" >" + EncodeStr.substr(0, 30) + "...</div>";
                                }
                                else {
                                    dsg = value;
                                }

 

 

//把特殊字符替换掉
function EncodeString(theString) {
    theString = theString.replace(/>/g, "&gt;");
    theString = theString.replace(/</g, "&lt;");
    theString = theString.replace(/\[/g, "&【;");
    theString = theString.replace(/]/g, "&】;");
    theString = theString.replace(/{/g, "&ldk;");//左大括号
    theString = theString.replace(/}/g, "&rdk;");//右大括号
    theString = theString.replace(/\\"/g, "&quot;");//双引号
    theString = theString.replace(/\\'/g, "#39;");//单引号
    theString = theString.replace(/\\/g, "\\\\");//对斜线的转义  
    theString = theString.replace(/\n/g, "\\n");//回车键
    theString = theString.replace(/\r/g, "\\r");
    theString = theString.replace(/\\",/g, "#42;");//双引号,
    theString = theString.replace(/&#/g, "#77;");//双引号,
    return theString;
}

//把特殊字符替换回来
function DecodeString(theString) {
    theString = theString.replace(/&gt;/g, ">");
    theString = theString.replace(/&lt;/g, "<");
    theString = theString.replace(/&【;/g, "[");
    theString = theString.replace(/&】;/g, "]");
    theString = theString.replace(/&ldk;/g, "{");//左大括号
    theString = theString.replace(/&rdk;/g, "}");//右大括号
    theString = theString.replace(/&quot;/g, "\"");
    theString = theString.replace(/#39;/g, "\'");
    theString = theString.replace(/\\\\/g, "\\");//对斜线的转义 
    theString = theString.replace(/\\n/g, "\n");//回车键
    theString = theString.replace(/\\r/g, "\r/");
    theString = theString.replace(/#42;/g, "\",");
    theString = theString.replace(/#77;/g, "&#");//双引号,
    return theString;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值