How to put Å, Ä and Ö in a javascript array and then compare it with html text?

你离开我真会死。 提交于 2019-12-11 06:27:02

问题


I want to put Å, Ä and Ö. And then compare them using html text. For example text has these characters, and i want to compare my text using javascript array. I am trying to make javascript array using following line of code:

 var array = ['Å', 'Ä', 'Ö'];

i even tried Å Ä and Ö. These codes work for html but not javascript. How can i do that? thanks in advance.


回答1:


Instead of storing string literals in the array, store their unicode representations:

var myArray = ['\u197', '\u196', '\u214'];

I used this website to convert your ASCII symbols to unicode.




回答2:


If your Javascript code is in a separate file than your HTML, you'll need to make sure that all of your files are using the same character encoding (e.g. utf-8). If you are using literals like this, you'll have to force your editor to use the correct encoding.

What editor are you using?



来源:https://stackoverflow.com/questions/12283369/how-to-put-%c3%85-%c3%84-and-%c3%96-in-a-javascript-array-and-then-compare-it-with-html-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!