表单序列化获取不到值的原因

本文探讨了在编写前端注册表单时,由于缺少name属性导致向后台提交数据时无法获取值的问题,强调了HTML表单元素中NAME属性的重要性。

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

在编写注册页面向后台提交表单数据时未获取到值:

<form class="form-horizontal" id="register_form">
                                <div class="form-group ">
                                    <label for="exampleInputUserId" class="col-sm-3 control-label">用户名</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="exampleInputUserId"  placeholder="请输入用户名">
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword" class="col-sm-3 control-label">密码</label>
                                    <div class="col-sm-9">
                                        <input type="password" class="form-control" id="exampleInputPassword" placeholder="请输入密码">
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputName" class="col-sm-3 control-label">姓名</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="exampleInputName" placeholder="请输入姓名">
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputEmail" class="col-sm-3 control-label">邮箱</label>
                                    <div class="col-sm-9">
                                        <input type="email" class="form-control" id="exampleInputEmail" placeholder="请输入邮箱">
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPhone" class="col-sm-3 control-label">电话</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="exampleInputPhone" placeholder="请输入电话">
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputIdCard" class="col-sm-3 control-label">身份证号</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="exampleInputIdCard" placeholder="请输入身份证号">
                                        <span class="help-block"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">性别</label>
                                    <div class="col-sm-9">
                                        <!--<%&#45;&#45;把单选按钮的代码复制到这里 M 代表男 F 代表女&#45;&#45;%>-->
                                        <label class="radio-inline">
                                            <input type="radio" name="gender" id="inlineRadio1" value="M"
                                                   checked="checked">
                                            男
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="gender" id="inlineRadio2" value="F">
                                            女
                                        </label>
                                    </div>
                                </div>
                                <button type="button" class="btn btn-primary btn-lg btn-block" id="register_btn">注册</button>
                            </form>

原因:

<input …>标签未加name属性

VBS获取表单里空间的值是根据NAME属性来的,ID的作用通常只是前台JS验证用的。
所以NAME属性是必不可少的,相反ID是可以省略的。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值