单击“提交”按钮后,如何刷新文本字段?

时间:2016-10-04 07:41:29

标签: html ionic-framework

我正在尝试在登录后清空html上的文本字段。注销后,我插入的数据仍然存在。我怎么做?这是我的HTML,谢谢你的帮助。

<div class="tabs-striped  tabs-background-positive tabs-color-light">
    <div class="tabs">
      <a class="tab-item active" href="#/app/login"><i class="icon ion-unlocked"></i> Login</a>
      <a class="tab-item" href="#/app/signup"> <i class="icon ion-person"></i> Sign Up </a>
    </div>
 </div>

<ion-view view-title="Sign In" class="loginBg" hide-nav-bar="true" >

  <ion-content class="padding">

    <div class="row responsive-sm padding remvoeBP">
        <div class="col">
            <center><img src="img/logo.png" alt="Item Img" width="275" height="90"></center>
            <br>
            <div class="list list-inset">
                <label class="item item-input">
                  <input  type="text" id="phone" placeholder="Phone Number" ng-model="user.phone" ng-maxlength="13" onkeypress='return event.charCode>=48 && event.charCode<=57' required autocomplete="off">
                </label> 

                <label class="item item-input">
                  <input type="password" id="pin" placeholder="PIN" ng-model="user.pin" ng-maxlength="6" onkeypress='return event.charCode>=48 && event.charCode<=57' required autocomplete="off">
                </label>
             </div>

            <div class="loginButton">
                <button class="button ion-unlocked button-block button-positive" ng-click="login();" > 
                    Login 
                </button>  
            </div>
        </div>
    </div>

  </ion-content>
</ion-view>

2 个答案:

答案 0 :(得分:0)

您可以尝试使用这样的jquery:

<script>
$(document).ready(function(){
$('form').each(function() { 
this.reset() 
});
});
<script>

答案 1 :(得分:0)

如果您使用的是jquery,请使用:

您可以使用 - $("#myform")[0].reset();重置表单 或

$('#form-id').children('input').val('')

如果您使用的是JavaScript:

<input type="button" value="Submit" id="btnsubmit" onclick="submitForm()">

function submitForm() {
   // Get the first form with the name
   // Hopefully there is only one, but there are more, select the correct index
   var frm = document.getElementsByName('contact-form')[0];
   frm.submit(); // Submit
   frm.reset();  // Reset
   return false; // Prevent page refresh
}

希望它有所帮助。

可能重复:How do i clear the previous text field value after submitting the form with out refreshing the entire page