数组中的变音符号不会转换

编程入门 行业动态 更新时间:2024-10-28 09:25:15
本文介绍了数组中的变音符号不会转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的小组成员, 我在Javascript中遇到了一个小故障,我不知道如何解决它 优雅。 我有一个包含德语单词串的数组: profile [1] =&Fr; hliches Fr?ulein" ;; 因为HTML不允许或者不允许其中某些字符,我写道: profile [1] =" Fr& ouml ; hliches Fr& auml; ulein" ;; 但是当我使用警报时(个人资料[1]);对话框显示转义 代码而不是变音标记。然后我想到了unescape() 函数会解决问题,但不是。我不想写: profile [1] =" Fr%190hliches Fr%191ulein"; alert(unescape(profile [ 1])); 上例中的数字仅用于说明这个想法。我不知道在哪里查看确切的数字,除非它们是 ASCII码。我还没有尝试过最后一种技术,但我正在思考 这个问题 任何建议, Jean Biver ________________________________________________ 查看我的主页 homepage.internet.lu/aibiver 请在 setiathome2.ssl.berkeley.edu/...dback& ; id = 26539

Dear group members, I cam across a glitch in Javascript and I don''t know how to solve it elegantly. I have an array with strings of German words: profile[1] = "Fr?hliches Fr?ulein"; Because HTML doesn''t or didn''t allow some of these characters, I wrote: profile[1] = "Fröhliches Fräulein"; but when I use an alert(profile[1]); the dialog displays the escape codes instead of the diacritical marks. I then figured the unescape() function would solve the problem, but not. I don''t want to write: profile[1] = "Fr%190hliches Fr%191ulein"; alert(unescape(profile[1])); The numbers in the above example only serve to illustrate the idea. I don''t know where to look the exact numbers up, unless they are the ASCII codes. I haven''t tried the last technique yet, but I''m pondering the issue Any suggestions, Jean Biver ________________________________________________ Check out my home page at homepage.internet.lu/aibiver Please recommend my seti@home profile at setiathome2.ssl.berkeley.edu/...dback&id=26539

推荐答案

2005年11月11日07:09:43 -0800,jiverbean写道: On 11 Nov 2005 07:09:43 -0800, jiverbean wrote: 我在Javascript中遇到了一个小故障而且我不知道如何解决它优雅。 我有一个包含德语单词串的数组: profile [1] =Fr?hliches Fr?ulein; 因为HTML不是或不允许其中一些字符 I cam across a glitch in Javascript and I don''t know how to solve it elegantly. I have an array with strings of German words: profile[1] = "Fr?hliches Fr?ulein"; Because HTML doesn''t or didn''t allow some of these characters

然后你需要为你的文档使用不同的字符集。试试 ISO-8859-1,它允许标准的欧洲口音字符。 - 萨法拉(Stephen Morley) www.safalra/programming/javascript/

jiverbean写道: jiverbean wrote: 我有一个包含德语单词串的数组: profile [1] =Fr?hliches Fr?ulein; 因为HTML不允许或不允许其中某些字符, 这是一个可能永远不会消亡的都市传奇。 HTML允许这些 字符,HTTP是并且一直是8位安全的。您只需要使用Content-Type标头声明 ,并且,对于离线使用, < head> < meta http-equiv =" Content-Type"含量=" text / html的; charset = ..."> ... < / head> 逃离的好理由8位字符_in HTML_正在编辑 不同的平台,没有知识或设施(由于键盘布局 键盘布局)在那里输入它们。 < http://www.htmlhelp/faq/html/design.html#entity-or-number> 我写道: profile [1] =" Fr& ouml; hliches Fr& auml; ulein" ;; JS(编程语言)不是HTML(标记语言)。这个源代码 必须由JS引擎解释,它不会也不会被认为是知道的。如何处理SGML字符实体引用,如& ouml;。 你必须解决没有问题。 但是当我使用警报(个人资料[1]);对话框显示转义代码而不是变音标记。然后我想到了unescape()函数会解决问题,但不是。我不想写: profile [1] =&#Fr%190hliches Fr%191ulein"; alert(unescape(profile [1])); 无论如何都不应该工作。 unescape(),这是专有的, 只接受8位转义序列(与标准化的 decodeURI *()相反)。以上结果 Fr< EM> 0hliches Fr< EM> 1ulein 其中< EM>是代码点0x19(31)处的字符。 ________________________________________________ [...] I have an array with strings of German words: profile[1] = "Fr?hliches Fr?ulein"; Because HTML doesn''t or didn''t allow some of these characters, That''s an urban legend that will probably never die. HTML allows these characters, HTTP is and has been 8-bit-safe. You just need to declare that with the Content-Type header and, for offline use, <head> <meta http-equiv="Content-Type" content="text/html; charset=..."> ... </head> A good reason for escaping 8-bit characters _in HTML_ is editing on different platforms without having the knowledge or facility (due to keyboard layout) to type them there. <www.htmlhelp/faq/html/design.html#entity-or-number> I wrote: profile[1] = "Fr&ouml;hliches Fr&auml;ulein"; JS (programming language) is not HTML (markup language). This source code has to be interpreted by the JS engine, and it does not and is not supposed to "know" how to handle SGML character entity references like "&ouml;". There is no problem you have to work around. but when I use an alert(profile[1]); the dialog displays the escape codes instead of the diacritical marks. I then figured the unescape() function would solve the problem, but not. I don''t want to write: profile[1] = "Fr%190hliches Fr%191ulein"; alert(unescape(profile[1])); It is not supposed to work anyway. unescape(), which is proprietary, accepts only 8-bit escape sequences (in contrast to standardized decodeURI*()). The above results in Fr<EM>0hliches Fr<EM>1ulein where <EM> is the character at code point 0x19 (31). ________________________________________________ [...]

签名将被分隔通过仅包含 - < SP>< CR>< LF>的行。 HTH PointedEars(德语)

Signatures are to be delimited by a line containing only "--<SP><CR><LF>". HTH PointedEars (a German)

jiverbean写道: jiverbean wrote: 亲爱的小组成员, 我在Javascript中遇到了一个小故障,我不知道我知道如何解决它优雅。 我有一个包含德语单词串的数组: profile [1] =&#Fr?hliches Fr? ulein英寸; 这些单词在数组中的事实并不重要。 你可能遇到的问题是你的编码/> html和/或保存的javascript与您在HTML中指定的 编码的编码不同。或者您可能忘记指定 编码并且错误地自动检测到编码。 在您的情况下最有用的编码可能是UTF-8。 因此,请确保在标题中包含此内容: < meta http-equiv =" Content-Type"含量=" text / html的; charset = utf-8" /> 接下来确保您的html / javascript文件是UTF-8格式。 我自己使用emeditor作为一个文本编辑器,因为它使用正确的 Unicode术语来保存文件。 因为HTML不允许或不允许其中一些字符,我写道: 个人资料[1] =&Fr& ouml; hliches Fr& auml; ulein" ;; 但当我使用警报时(个人资料[1] ]);对话框显示转义代码而不是变音标记。 Dear group members, I cam across a glitch in Javascript and I don''t know how to solve it elegantly. I have an array with strings of German words: profile[1] = "Fr?hliches Fr?ulein"; The fact that these words are in an array doesn''t matter. The problem that you are probably having is that the encoding that your html and/or javascript is saved is in a different encoding than the encoding you specified in your HTML. Or maybe you forgot to specify the encoding and the encoding is wrongly auto-detected. The most useuful encoding in your case is probably UTF-8. So makes sure you have this in your header: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> Next make sure that your html/javascript file is in UTF-8 format. I myself use emeditor as a text editior, because it uses the correct Unicode terminology for saving files. Because HTML doesn''t or didn''t allow some of these characters, I wrote: profile[1] = "Fr&ouml;hliches Fr&auml;ulein"; but when I use an alert(profile[1]); the dialog displays the escape codes instead of the diacritical marks.

那是因为javascript不是html。 Javascript还有其他机制 用于转义任何unicode字符的\ u等字符。 所以你可以写 profile [1] =Fr\\\öhliches Fr\\\äulein; 如果你想用不同的编码保存你的文件作为你的输出。 罗伯特。

That''s because javascript is not html. Javascript has other mechanisms for escaping characters such as the \u for any unicode character. So you can write profile[1] = "Fr\u00F6hliches Fr\u00E4ulein"; if you want to save your file in a different encoding as your output. Robert.

更多推荐

数组中的变音符号不会转换

本文发布于:2023-10-26 22:59:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组中   符号

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!