javascript - Degree unicode showing as Question Mark - Stack Overflow

The following code shows up as a question mark instead of a degree sign:var airF = Math.round(Number(MD

The following code shows up as a question mark instead of a degree sign:

var airF = Math.round(Number(MDTMOBILE.RWISWeather[i].AirTemp)) + "\u00B0" + "F";
$('.tempTable').find('td').eq(4).text(airF);
var relHum = Math.round(MDTMOBILE.RWISWeather[i].RH) + "%";
$('.tempTable').find('td').eq(5).text(relHum);
var dewF = Math.round(Number(MDTMOBILE.RWISWeather[i].Dewpoint)) + "\u00B0" + "F";
$('.tempTable').find('td').eq(6).text(dewF);

It displays as: Temp RH Dew 54�F 38% 29�F

Am I using the wrong unicode? "\u00B0"

The following code shows up as a question mark instead of a degree sign:

var airF = Math.round(Number(MDTMOBILE.RWISWeather[i].AirTemp)) + "\u00B0" + "F";
$('.tempTable').find('td').eq(4).text(airF);
var relHum = Math.round(MDTMOBILE.RWISWeather[i].RH) + "%";
$('.tempTable').find('td').eq(5).text(relHum);
var dewF = Math.round(Number(MDTMOBILE.RWISWeather[i].Dewpoint)) + "\u00B0" + "F";
$('.tempTable').find('td').eq(6).text(dewF);

It displays as: Temp RH Dew 54�F 38% 29�F

Am I using the wrong unicode? "\u00B0"

Share Improve this question asked Oct 23, 2013 at 19:22 WacWac 6881 gold badge6 silver badges13 bronze badges 4
  • 3 What's your page's charset? – Michael Krelin - hacker Commented Oct 23, 2013 at 19:23
  • page's charset = <meta charset="utf-8"> – Wac Commented Oct 23, 2013 at 21:03
  • Turns out my script minify process removed the \u00B0 and replace with a degree symbol, change the min script and it works fine. Thanks for the suggestions. – Wac Commented Oct 24, 2013 at 13:24
  • That means your javascript is not served as unicode. Otherwise replacing with a degree symbol would do no harm. – Michael Krelin - hacker Commented Oct 24, 2013 at 14:42
Add a ment  | 

3 Answers 3

Reset to default 4

The notation "\u00B0" is a correct way to use the degree sign in a character literal. But you can also write the character directly, "°", provided that character encoding has been selected and announced properly, as it should.

If you see “�” on a web page, the most mon reason is that the character encoding of an HTML document is windows-1252 (or iso-8859-1) but the declared encoding is utf-8. However, in this case, such problems should not arise, because the string is generated in JavaScript, and JavaScript and the DOM internally use UTF-16 for characters data, no matter what the document’s encoding is. To analyze what goes wrong, I think we need a self-contained demo that reproduces the problem, and/or a URL of a demo.

I suspect your page is not unicode, but even then you can use .html('&#x00b0;') instead — I believe it should work.

If your jQuery is on a JSP page, you can try this

<%@ page contentType="text/html; charset=UTF-8" %>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744252525a4565235.html

相关推荐

  • javascript - Degree unicode showing as Question Mark - Stack Overflow

    The following code shows up as a question mark instead of a degree sign:var airF = Math.round(Number(MD

    8天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信