Issues with the accented characters

落爺英雄遲暮 提交于 2019-12-06 10:11:35

Have you used <script type="application/javascript" charset="utf-8" src="yourfile.js"></script>"? (Assuming your file is saved as utf-8, of course.)

If you are going to use those special characters in HTML, it may be an idea to use this String replace method for all special characters:

[somestring].replace(/[\u0080-\u024F]/g,
                      function(a) {
                        return '&#'+a.charCodeAt(0)+';';
                      });

It will convert all special characters to numeric html entities and prevent the need to type all those characters in your javascript, e.g.

 'ñíóúü¡¿'.replace(.replace(/[\u0080-\u024F]/g,
                      function(a) {
                        return '&#'+a.charCodeAt(0)+';';
                      });
  //=> result
  // &#241;&#237;&#243;&#250;&#252;&#161;&#191;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!