spanish characters not coming properly in javascript?

十年热恋 提交于 2019-12-13 04:23:51

问题


Hi I am using the following regular expression.It works fine in jsfiddle here.

                     var string="zñáéíóúü1111";

                       if(/^[0-9a-zñáéíóúü]+$/i.test(string))
                {
                    $("#result").text("oK WITH THE INPUT");

                }
                else
                {
                        $("#result").text("error");

                }

But when I put the code in browser the spanish characters not coming proprely(Some strange characters) (view source code in browser). and the above regular expression not working properly.

But I have the

 <meta http-equiv="content-type" content="text/html;charset=utf-8" />

in the browser.

I am not sure about the reason why its not working on my page , when I am getting the input from the user.But I put alert and checked the characters in this string .Both are same.


回答1:


I guess your HTML or JS file or both of them are not saved as UTF-8. You should adjust your editor's charset settings. Depending on the editor you might find them in the save dialog or the files' properties.




回答2:


Follow the below link http://character-code.com/spanish-html-codes.php

for n = &nacute; for i = &iacute;



来源:https://stackoverflow.com/questions/17246076/spanish-characters-not-coming-properly-in-javascript

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