form表单重置

xiaoxiao2025-05-19  39

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


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(); });

 

转载请注明原文地址: https://www.6miu.com/read-5030370.html

最新回复(0)