简体   繁体   English

Javascript HTML瑞典语字符奇怪的行为

[英]Javascript Html Swedish characters strange behavior

I would like to ask a question regarding a strange behavior I face using the escape Ascii characters for some Swedish chars. 我想问一个关于我使用一些瑞典字符的转义Ascii字符时遇到的奇怪行为的问题。

More specifically, in order to support a multilingual site, I have a json file where I have specified all required messages in Swedish, ie 'Avancerad s& #246 ;k'. 更具体地说,为了支持多语言站点,我有一个json文件,其中以瑞典语指定了所有必需的消息,即“ Avancerad s& #246 ; k”。

Then when the page loads the first time, I set this value to an input text and it is displayed properly: 'Avancerad sök'. 然后,当页面首次加载时,我将此值设置为输入文本,并正确显示:“ Avanceradsök”。 But when I click a button and set again the value of this input text I get: 'Avancerad s& #246 ;k'. 但是,当我单击按钮并再次设置此输入文​​本的值时,我得到:'Avancerad s& #246 ; k'。

Does anyone have faced a similar problem? 有没有人遇到过类似的问题?

Thanks a lot! 非常感谢!

Code: 码:

q('#keyword').val(qLanguage.qAdvancedHint);

I execute this code both times. 我两次都执行此代码。 qLanguage is an object which I fill it from the json file and qAdvancedHint a specific key. qLanguage是一个对象,我从json文件填充它,而qAdvancedHint是一个特定的键。

Don't know have the specific encoding is called. 不知道是否调用了特定的编码。 But tested with js's unescape method, but didn't work. 但是用js的unescape方法进行了测试,但是没有用。

However a solution, a bad/ugly one, could be to ask jQuery to parse it for you then add it as a value property: 但是,一种解决方案(不好/很丑陋)可能是让jQuery为您解析它,然后将其添加为value属性:

var text = $("<span/>").html(qLanguage.qAdvancedHint).text();
q('#keyword').val(text);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM