Skip to content

Instantly share code, notes, and snippets.

@awn-git
Created December 26, 2016 18:10
Show Gist options
  • Save awn-git/2ae01b09da0243b983e83c8585ee6516 to your computer and use it in GitHub Desktop.
Save awn-git/2ae01b09da0243b983e83c8585ee6516 to your computer and use it in GitHub Desktop.
(あとで書く)textareaのvalueメソッド vs textareaが属するformをFormDataに突っ込んでからvalueを取得する

(あとで書く)textareaのvalueメソッド vs textareaが属するformをFormDataに突っ込んでからvalueを取得する

要点

  • 改行コードが異なる
    • 前者はLF(改行)のみ
    • 後者はLF(改行)CR(復帰)
  • となる

検証

https://jsbin.com/zarodixota/edit?html,js,console,output

以下コード

"----------------"
97
10
98
10
10
99
10
10
100
10
"-----------------"
97
13
10
98
13
10
13
10
99
13
10
13
10
100
13
10
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<form name="test">
<textarea name="text1">
a
b

c

d
</textarea>
</form>
</body>
</html>
let form = document.forms["test"];
let text = form["text1"].value;
console.log("----------------");
for(let char of text){
  console.log(char.charCodeAt());
}

let fd = new FormData(form);
console.log("-----------------");
for(let value of fd){
  let str = value[1];
  for(let char of str){
    console.log(char.charCodeAt());
  }
}
@awn-git
Copy link
Author

awn-git commented Dec 26, 2016

訂正

🙅‍♀️

改行コードが異なる

  • 前者はLF(改行)のみ
  • 後者はLF(改行)CR(復帰)
    となる

🙆‍♀️

改行コードが異なる

  • 前者はLF(改行)のみ
  • 後者はCR(復帰)LF(改行)
    となる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment