[LayaAir2]记录Laya.HTMLDivElement的坑
如果内容是包含特殊符号,就会报错
解决方案:把内容替换
var divElement = new Laya.HTMLDivElement();
var textWithSpecialChars = 'This is some text with <, >, &, ", \', ©, ®, €, ¥, °, ±, ×, ÷ characters';
textWithSpecialChars = textWithSpecialChars.replace(/[<>&"']/g, function(match) {
return {
'<': '<',
'>': '>',
'&': '&',
'"': '"',
"'": '''
}[match];
}).replace(/©/g, '\u00A9')
.replace(/®/g, '\u00AE')
.replace(/€/g, '\u20AC')
.replace(/¥/g, '\u00A5')
.replace(/°/g, '\u00B0')
.replace(/±/g, '\u00B1')
.replace(/×/g, '\u00D7')
.replace(/÷/g, '\u00F7');
divElement.innerHTML = textWithSpecialChars;
解决方案:把内容替换
var divElement = new Laya.HTMLDivElement();
var textWithSpecialChars = 'This is some text with <, >, &, ", \', ©, ®, €, ¥, °, ±, ×, ÷ characters';
textWithSpecialChars = textWithSpecialChars.replace(/[<>&"']/g, function(match) {
return {
'<': '<',
'>': '>',
'&': '&',
'"': '"',
"'": '''
}[match];
}).replace(/©/g, '\u00A9')
.replace(/®/g, '\u00AE')
.replace(/€/g, '\u20AC')
.replace(/¥/g, '\u00A5')
.replace(/°/g, '\u00B0')
.replace(/±/g, '\u00B1')
.replace(/×/g, '\u00D7')
.replace(/÷/g, '\u00F7');
divElement.innerHTML = textWithSpecialChars;
没有找到相关结果
已邀请:
要回复问题请先登录
0 个回复