提交表单 JQ 获取所有input输入框的值

版权声明:转载需附上本文地址 https://blog.csdn.net/weikaixxxxxx/article/details/89598829

之前要用ajax只会一个一个的获取input里的值,然后再拼接成json格式。当表单项多的时候就很烦了。

 <form id="form">
    <input type="text" name="username"/>
    <input type="text" name="password"/>
    <button type="button" id="login">登录</button>
</form>
<script>
    $('#login').click(function () {
    	$.post("{:url('')}", $('#form').serialize(),function (data) {
            console.log(data);
        })
    })
</script>		

后台return的输出
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weikaixxxxxx/article/details/89598829