jquery 怎么把 form 表单序列化成一个对象

本文介绍了一个简单的JSP页面示例,该页面使用jQuery进行表单元素的值收集,并通过控制台输出这些值。示例展示了如何在JSP中引入jQuery库并利用jQuery选择器获取表单字段的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="js/jquery-1.8.2.js" charset="UTF-8"></script>
    <script type="text/javascript">
        var args = {};
        function send(){
            var v = $("form").find(":input,textarea").each(function(){
                 if (this.name != "" && this.type != "button") {
                    if ($(this).val() != "") {
                        args[this.name] = $.trim($(this).val());
                    }
                 }
            });
            console.info(args);
        }
    </script>
  </head>
 
  <body>
    <form id="form1" action="">
        <table>
            <tr><td>用户名</td><td><input type="text" name="name"/></td></tr>
            <tr><td>密码</td><td><input type="password" name="pwd"></td></tr>
        </table>
    </form>
    <input type="button" value="提交" onclick="send()">
  </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值