问题与重音字符 [英] Issues with the accented characters
问题描述
我的网站上有一个搜索框,我需要将用户输入的所有西班牙字符替换为相应的英文字母。我的编码如下图所示。这在我将其插入到我的项目中时甚至在创建一个相同编码的简单html页面时不起作用。我的页面使用< meta charset =utf-8/>
。当我创建一个小提琴 http://jsfiddle.net/KJAy3/ 时,这是正常的。这是它如何在调试器中显示
I have a search box on my site and i need to replace all the Spanish characters that user types in to equivalent English alphabets. I have coded which is shown below. This is not working when i plug in it to the my Project and even when create a simple html page which coded same. My page is using <meta charset="utf-8" />
. This is working fine when i created a fiddle http://jsfiddle.net/KJAy3/. This is how it it is show in the debugger
我做错了什么?我应该用什么样的编码?此替换方法在表单提交之前触发。
What am i doing wrong? What kind of encoding i am supposed to us? This Replace method is triggered before the form submit.
function encodeSearch(term){
term=term.replace("á","a");
term=term.replace("Á","A");
term=term.replace("é","e");
term=term.replace("É","E");
term=term.replace("í","i");
term=term.replace("Í","I");
term=term.replace("ó","o");
term=term.replace("Ó","O");
term=term.replace("ú","u");
term=term.replace("Ú","U");
term=term.replace("ñ","n");
term=term.replace("Ñ","N");
return term;
}
推荐答案
您是否使用过< script type =application / javascriptcharset =utf-8src =yourfile.js>< / script>
?(假设您的文件保存为utf-8,当然。)
Have you used <script type="application/javascript" charset="utf-8" src="yourfile.js"></script>"
? (Assuming your file is saved as utf-8, of course.)
这篇关于问题与重音字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!