I am writing a basic HTML5 with some JavaScript.
I am using the following doctype:
<!DOCTYPE html>
And I have set my UTF-8 encoding like do (in the head tag):
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
The problem is, I have this javascript object which looks is exactly like this:
var symbol = {"GBP":"£", "EUR":"€", "USD":"$"};
alert(symbol['GBP']);
When the object is called it returns with the infamous !
Could somebody please point me in the right direction?
Thanks,
Peter
Some steps you don't mention:
Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8
What editor do you use? There is a possibility that you editor saves file in some iso8859 encoding. Try to use for example notepad and save file in UTF-8 encoding.
可能是您可以改用HTML实体。
var symbol = {"GBP":"£", "EUR":"€", "USD":"$"};
So it turns out, when you use the alert function, it doesn't like using special characters. My code was absolutely fine when I used the special characters in the HTML document. So instead I used something like this:
$(this).html(symbol['GPB']);
Thanks for your effort guys!
Peter
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.