1
基本的には、生のフィールド値を読み込もうとしていますが、以下のようにはできません。予想通り、私は入力通常の電子メールは、Javascriptが値を読み取ることができ中国語とラテン文字が混在した電子メールフィールドからの生の値の取得
<input type="email" name="username" id="username" />
:
は、簡単なメールフォームフィールドを考えてみましょう。私はすべての中国語文字を入力すると、Javascriptも期待どおりの値を読み取ることができます。 しかし、ラテン文字と中国語文字を混在させると、Javascriptはある種のコード文字セットに変換されるようです。試験例:
[email protected] //returns [email protected] 暮捕徹@暮捕徹.暮捕徹 //returns 暮捕徹@暮捕徹.暮捕徹 [email protected]暮捕徹.com //returns [email protected] [email protected]暮捕徹 //returns [email protected]
テストコード:私が試した
function login(){
\t var username=document.querySelector('#username').value;
var resultDiv=document.createElement('DIV');
resultDiv.innerText = username;
\t document.querySelector('body').appendChild(resultDiv);
return false;
}
<form onsubmit="javascript: return false;">
<label for="username">Username</label>
<input type="email" name="username" id="username" />
<button onclick="login();">
Login
</button>
</form>
もの:
私は<head>
に設定されている
- :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- 私は、フォームフィールドでUTF-8を設定していた:
<input type="email" name="username" id="username" accept-charset="utf-8" />
Giboltの答えに基づいて、私は入力データの要件の一部としてpunycodeを組み込み、この変換された文字列に基づいてデータを処理しました。 – EdC