「jQuery」serialize()で入力文字列をシリアライズするサンプル

書式
$(“divセレクター").text($(“form").serialize());
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#gt").click(function(){
$(".info").text($("form").serialize());
});
});
</script>
</head>
<body>
<form action="">
ユーザ名: <input type="text" name="username" value="yamada"><br>
住所: <input type="text" name="address" value="testaddrree"><br>
</form>
<button id="gt">シリアライズ</button>
<div class="info"></div>
</body>
</html>
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#gt").click(function(){ $(".info").text($("form").serialize()); }); }); </script> </head> <body> <form action=""> ユーザ名: <input type="text" name="username" value="yamada"><br> 住所: <input type="text" name="address" value="testaddrree"><br> </form> <button id="gt">シリアライズ</button> <div class="info"></div> </body> </html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#gt").click(function(){
    $(".info").text($("form").serialize());
  });
});
</script>
</head>
<body>

<form action="">
  ユーザ名: <input type="text" name="username" value="yamada"><br>
  住所: <input type="text" name="address" value="testaddrree"><br>
</form>

<button id="gt">シリアライズ</button>

<div class="info"></div>

</body>
</html>

 

jQuery

Posted by arkgame