jQuery解析字符串中的unicode characthers

时间:2017-10-12 17:48:41

标签: javascript jquery parsing unicode unicode-escapes

我有一个基本上看起来像这样的字符串:

20 pcs 1/4" d 13/32" l shank copper round head solid rivets fasteners

或:

20 Pcs 1/4" D 13/32" L Shank Copper Round Head Solid Rivets Fasteners

哪里"应表示为:" characther ...

在我的JS方法中,我将标签值设置为以下:

function WriteTitle(sentTitle){
 $("#myTitle").text(sentTitle);
}

我尝试使用像decodeURIComponent,unescape或类似方法来解析这些字符,但到目前为止还没有运气......

如何将这些解析成普通字符?

1 个答案:

答案 0 :(得分:1)

这些不是unicode字符,而是HTML entities。你应该使用.html()方法,它不会逃避它们(这正是.text()所做的)。

function WriteTitle(sentTitle){
  $("#myTitle").html(sentTitle);
}