Jump to content

In JavaScript String charCodeAt() Method Chapter , I use Chinese word for test string, but I can not get the correct unicode result.


wubaie

Recommended Posts

I mean the same Javascript code in w3school [try it yourself] and in a real html file.

But the return unicode result is not same.

I think w3school have not the correct simulation coding in JavaScript String charCodeAt() Method Chapter.

Link to comment
Share on other sites

This code?

 

http://www.w3schools.com/js/tryit.asp?filename=tryjs_string_charcodeat

 

I believe the article I mentioned above says that Javascript itself does not handle all unicode correctly.

<!DOCTYPE html><html><head><meta charset="utf-8"/><title>utf-8</title><style></style><script>window.onerror = function(a, b, c, d){alert('Javascript Error:n'+a+'nURL: '+b+'nLine: '+c+'  Column: '+d);return true;}</script><script>'use strict';window.onload = init;function init() {document.getElementById('btn1').onclick = put;}function put(){var str = "Iñtërnâtiônàlizætiøn☃.";var str2 = "";for(var i=0,len=str.length ; i<len ; i++){  str2 += str.charAt(i) + "=" + str.charCodeAt(i) + " ";}document.getElementById("out").innerHTML = str2;}</script></head><body><p>Iñtërnâtiônàlizætiøn☃.</p><input type="button" id="btn1" value="Enter"><div id="out"></div></body>    </html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...