Last active
January 24, 2020 13:58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> | |
<!--入力画面作成--> | |
<textarea id="newlineTest1" class="sample3" cols="40" rows="8"> | |
改行をいれてみよう | |
</textarea> | |
<textarea id="newlineTest2" class="sample3" cols="40" rows="8"> | |
改行をいれてみよう | |
</textarea> | |
</form> | |
<button id="btn" type="submit" name="example" value="ボタン" >JSON書き出し</button> | |
<!--jQueryライブラリの読み込み--> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
<!--Javascript開始--> | |
<script> | |
$('#btn').click(function(){ | |
//JSONの入れ物jsonの作成 | |
let json = {}; | |
//画面の値取得、jsonに格納 | |
json.newlineTest1 = $('#newlineTest1').val(); | |
json.newlineTest2 = $('#newlineTest2').val(); | |
//改行ありjsonの確認 | |
console.log(json); | |
//jsonをstring(文字列)に変換 | |
let jsonStr = JSON.stringify(json); | |
//文字列から改行コードを削除 | |
let json2 = jsonStr.replace( /\\n/g , ''); | |
console.log(json2); //改行削除後 | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment