HTML Form中button自动刷新页面

<form class="form form-horizontal" id="queryForm" >
            <div class="row cl">
                <label class="form-label col-sm-3">服务号码:</label>
                <div class="formControls col-sm-4">
                    <input type="text" class="input-text" placeholder="输入手机号码" id="cellNo" name="cellNo">
            <div class="row cl">
                <div class="formControls col-sm-4 col-sm-offset-3">
                    <button class="btn btn-success radius" id="queryBtn">查询</button>
<button type="button" class="btn btn-success radius" id="queryBtn">查询</button>

发布了19 篇原创文章 · 获赞 17 · 访问量 1万+



<div class="post-text" itemprop="text"> <p>I have a Iframe which has a form with text fields.This form is created by php script. The parent page refresh auto, continuously.</p> <pre><code><form id="form" method="post" action="test.php?vid='.$vid.'"> <table border="1" width="100%" style="border-collapse:collapse"> <tr> <th class="col-header list">Distance </th> <th class="col-header list">Service</th> <th class="col-header list">Recipient</th> </tr> <tr> <td > <input type="text" class="input" id="cdistance" name="cdistance" /> </td> <td nowrap class="list"> <input type="text" class="input" id="service" name="service" /> </td> <td nowrap class="list"> <input type="text" class="input" id="destination" name="destination" /> </td> </tr> <tr> <td width="100%" colspan="3" style="background:#e0e0e0;"> <input type="submit" class="btn" name="add" id="add" value="Add New"/> <input type="hidden" name="distance_unit" value="'.$distance.'" /> </td> </tr> </table> </form> </code></pre> <p>To avoid user entered data loosing ('before hit submit') I used query code in parent page to get those entered text in Iframe's form and add them back to text fields after page refreshed.</p> <p>My problem is when the user hit the submit button after page refreshed text fields are not cleared (form not reset) but data submitted successfully.So I tried to reset the form by <code>$('#form')[0].reset()</code>. This is the error I got </p> <blockquote> <p>Uncaught TypeError: Cannot read property 'reset' of undefined</p> </blockquote> <p>Also tried <code>$('#textVal').val('');</code> to empty text fields. But still the data remaining in text fields.</p> <p>Note: The form is reset if the user hit submit button before refreshed. Does anyone need more details please let me know. </p> <p>Any solution for this would be appreciated. </p> </div> 问答


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客