码迷,mamicode.com
首页 > Web开发 > 详细

jquery-ajax中的serialize()

时间:2019-07-07 21:35:24      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:pat   serial   ack   val   alt   序列   col   value   har   

serialize()方法是将表单文本序列化,生成 URL 编码文本字符串

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="jquery-3.4.1.js"></script>
    <script>
    $(document).ready(function(){
        $(button).click(function(){
            $(#div2).text($(form).serialize());
        })
    })
    </script>
    <style>
        #div2{
            font-size: 20px;
            color: red;
        }
    </style>
</head>
<body>
    <form action="">
       姓名:<input type="text" name=‘name‘ value="WuKong"><br><br>
       年龄:<input type="text" name= ‘age‘ value=‘666‘>
    </form><br><br>
    <button>点一下</button>
    <div id="div2"></div>
</body>
</html>

 

  页面内容:

技术图片

点击按钮之后

技术图片

如果把文本内容换成汉字

   <form action="">
       姓名:<input type="text" name=‘name‘ value="悟空"><br><br>
       年龄:<input type="text" name= ‘age‘ value=‘666‘>
    </form><br><br>

  刷新页面,点击按钮

  技术图片

 

jquery-ajax中的serialize()

标签:pat   serial   ack   val   alt   序列   col   value   har   

原文地址:https://www.cnblogs.com/zhangcheng001/p/11147900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!