form-serialize-serializeArray-submit

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>attr-prop</title>

    <style>
       
    </style>
 
</head>
<body>
 
    <!--
        1 serialize()

        2 serializeArray()

        3 submit()

     -->
    <form   method="post">
        <input type="text" name="val" value="kobe">
        <input type="password" name="pw" value="123">
        <input type="checkbox" checked="checked" name="rember">
        <input type="submit" value="按钮" name="anniu">
    </form>
     

    <script src="../zepto.js"></script>
    <script src="../touch.js"></script>
    <script>
        $(function(){
            var result = $('form').serialize()
            console.log(result);  // val=kobe&pw=123&rember=on

            result = $('form').serializeArray()
            // (3) [  {name: "val", value: "kobe"} {name: "pw", value: "123"} {name: "rember", value: "on"}length: 3__proto__: Array(0)
            console.log(result);  

            $('form').submit(function(event){
                event.preventDefault()
                alert('1')
            })
           
        })
    </script>

</body>
</html>
posted @ 2022-02-17 17:50  13522679763-任国强  阅读(33)  评论(0)    收藏  举报