From 9fdc48ba56640ccf6013d57b550aabe129dd843f Mon Sep 17 00:00:00 2001 From: gaojuan Date: Fri, 30 Mar 2018 16:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E6=83=85=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fangija-zsyf/views/news/newsDetail.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fangija-zsyf/views/news/newsDetail.html b/fangija-zsyf/views/news/newsDetail.html index 34d582c..e47913b 100644 --- a/fangija-zsyf/views/news/newsDetail.html +++ b/fangija-zsyf/views/news/newsDetail.html @@ -526,6 +526,7 @@ $(".commentReleaseBox a").on("click", function () { function addComment(){ var content = $(".commentReleaseBox input").val(); + content = utf16toEntities(content); axios.post("/rest/comment/add",{commentObjId : id, content:content, commentUserProvince:province, commentUserCity:city}).then(function (response) { var msg = response.data.message if(msg){ @@ -540,6 +541,25 @@ function addComment(){ }); } +function utf16toEntities(str) { + var patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则 + str = str.replace(patt, function(char) { + var H, L, code; + if (char.length === 2) { + H = char.charCodeAt(0); + // 取出高位 + L = char.charCodeAt(1); + // 取出低位 + code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; + //转换算法 + return "&#" + code + ";"; + } else { + return char; + } + }); + return str; +} + $(function() { $('#commentInput').on('click', function () { var target = this;