form表单重置

有时候我们需要重置一些表单元素,点击重置按钮的时候,清空表单元素,设置下拉框为默认值等,重置表单除非特殊情况,尽量使用表单自己的重置方法


html部分


<div class="main_content">
                <form id="user_info">
                    <table>
                        <tr>
                            <td class="topic">用户类型:</td>
                            <td class="user_type">
                                <select class="sel-types"> 
                                    <option value="">请选择用户类型</option>
                                    <option value="0">个人版</option>
                                    <option value="1">机构版</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="topic">用户姓名(机构名称):</td>
                            <td class="user_name">
                                <input type="text"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="topic">证件号码:</td>
                            <td class="ID_number">
                                <input type="text" name="idcard" id="idcard">
                            </td>
                        </tr>
                    </table>
                    <ul id="input-history" class="dsn">
                        <li>
                            <span class="left">用户名</span>
                            <span class="right">身份证号</span>
                        </li>
                    </ul>
                </form>
                <!-- 下一步按钮 -->
                <div class="fundNextButton">
                    <button id="ensure">确定</button>
                    <button id="user-reset">重置</button>
                </div>
            </div>

js部分


$('#user-reset').click(function(){
          // $(".ID_number input[type='text']").val('');
          // $(".sel-types option[value='']").attr("selected", true);
          $('#user_info')[0].reset()
          $(".user_name input[type='text']").val('').focus();
        });

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值