实际上,所有内容通常都在内部以某种Unicode形式存储,但不要赘述。我假设您正在使用标志性的“åäö”类型字符串,因为您使用的是ISO-8859作为字符编码。您可以采取一种技巧来转换这些字符。用于编码和解码查询字符串的escape和unescape函数是为ISO字符定义的,而较新的encodeURIComponent和decodeURIComponent功能相同的函数是为UTF8字符定义的。escape将扩展的ISO-8859-1字符(UTF代码点U + 0080-U + 00ff)%xx编码为(两位十六进制),而将UTF代码点U + 0100及更高版本编码为%uxxxx(%u后跟四位十六进制。)例如,escape("å") == "%E5"和escape("あ") == "%u3042"。encodeURIComponent将扩展字符百分比编码为UTF8字节序列。例如encodeURIComponent("å") == "%C3%A5"和encodeURIComponent("あ") == "%E3%81%82"。因此,您可以执行以下操作:fixedstring = decodeURIComponent(escape(utfstring));例如,错误编码的字符“å”变成“Ã¥”。该命令执行的操作escape("Ã¥") == "%C3%A5"是将两个错误的ISO字符编码为单个字节。然后decodeURIComponent("%C3%A5") == "å",将两个百分比编码的字节解释为UTF8序列。如果您出于某种原因需要做相反的事情,那也可以:utfstring = unescape(encodeURIComponent(originalstring));有没有办法区分错误的UTF8字符串和ISO字符串?原来有。如果给定格式错误的编码序列,则上面使用的encodeURIComponent函数将引发错误。我们可以使用它来很有可能检测我们的字符串是UTF8还是ISO。var fixedstring;try{ // If the string is UTF-8, this will work and not throw an error. fixedstring=decodeURIComponent(escape(badstring));}catch(e){ // If it isn't, an error will be thrown, and we can assume that we have an ISO string. fixedstring=badstring;}