西班牙语特殊字符,例如 á ó显示混乱或垃圾值时
我有一条西班牙语验证消息,我正在尝试使用 JavaScript 显示该消息。 所有像上面这样的特殊字符都会变成 & #243;。 只有当我使用 JavaScript 时才会发生这种情况,还有一些西班牙语验证消息,我通过服务器端显示它们,它们很好。
errorString = "<%:Validation.xyz %>";
我正在尝试从资源文件中获取。
有人能想到快速解决办法吗?
I have a Spanish validation message which I'm trying to display using my JavaScript.
And all the special characters like above gets changed into & #243;.
And it is only happening when I'm using JavaScript, there are couple of more validation messages in Spanish which I'm displaying through server side and they are fine.
errorString = "<%:Validation.xyz %>";
I'm trying to get from resource file.
Can some one think of quick work around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你所说的垃圾实际上只是相应字符的 HTML 编码值,它的作用是防止 XSS。发生编码是因为您使用
<%:
,它会自动对字符串进行 HTML 编码,但这对于您的 javascript 来说不应该是问题。示例:工作正常并在相应的 DOM 元素中显示
hello ó
。What you call garbage is actually but the HTML encoded value of the corresponding character and is there to prevent you from XSS. The encoding happens because you are using
<%:
which automatically HTML encodes the string but this shouldn't be a problem for your javascript. Example:works just fine and displays
hello ó
in the corresponding DOM element.检查您是否使用 UTF-8 编码保存文件(以防万一)。它碰巧进入没有 UTF8 BOM 的 TFS,然后客户端可能会发生混乱。
Check if you saved your file with UTF-8 encoding (just in case). It happens that it goes into TFS without UTF8 BOM and then mess can happen on client side.