Javascript 清除按钮角JS

Javascript 清除按钮角JS,javascript,angularjs,ionic-framework,ionic,Javascript,Angularjs,Ionic Framework,Ionic,我试图创建一个清除按钮来清空输入字段的值。到目前为止,它清除了用户名文本框,但之后我无法再次清除它,密码框也根本不清除 HTML: <div class="list"> <label class="item item-input"> <span class="input-label">Username</span> <input type="email" name="username" ng-model

我试图创建一个清除按钮来清空输入字段的值。到目前为止,它清除了用户名文本框,但之后我无法再次清除它,密码框也根本不清除

HTML:

<div class="list">
    <label class="item item-input">
        <span class="input-label">Username</span>
        <input type="email" name="username" ng-model="username" ng-minlength="5" required>
    </label>
    <label class="item item-input">
        <span class="input-label">Password</span>
        <input type="password" name="password" data-ng-model="password" ng-minlength="6" required>
     </label>
 </div>
这是一张工作票

HTML:

我发了一封信

HTML:


嗨,这个解决方案对我有效,请检查一下

    <ion-content ng-controller="ExampleCtrl">
          <div class="list">
                <label class="item item-input">
                    <span class="input-label">Username</span>
                    <input type="email" name="username" ng-model="form.username" ng-minlength="5" required>
                </label>
                <label class="item item-input">
                    <span class="input-label">Password</span>
                    <input type="password" name="password" data-ng-model="form.password" ng-minlength="6" required>
                </label>
                <button class="button button-bar button-balanced" ng-click="submit()">Submit</button>
<button class="button button-bar button-balanced" ng-click="clear()">Clear</button>
            </div>
          </ion-content>

如果有任何疑问,请回复

您能创建一个jsfidlle\plnkr吗?为什么在同一范围内有两个“提交”功能@sphaso您的示例需要做一个小的更改:$scope.clear=function(用户名、密码)应更改为$scope.clear=function()和console.log(用户名);console.log(密码);应该是console.log($scope.username);log($scope.password);哦,是的,谢谢,我没有看到,它们完全没用。我认为你的plunker还有其他问题,但在应用程序上它没有@如果没有完整的代码,michelemI无法知道你的应用程序中存在什么问题。我对我的代码进行了注释,只使用了你的代码,正如我所说,仅在应用程序中它不起作用。。它可能是离子细菌,还是其他什么@米切莱米:我认为它不起作用,你在哪里清除这些值?在
clear()
方法中只有
console.log()
在初始化控制器后,我将表单清除为
$scope.form=”“
并实现双向数据绑定,您可以通过实现此操作在代码中检查它。他要求单击按钮清除表单。您尝试了吗?不起作用是的,我知道了,我已经编辑了这篇文章,请检查一下
<div ng-app="myApp" ng-controller="dummy">
    <div class="list">
        <label class="item item-input"> <span class="input-label">Username</span>

            <input type="email" name="username" ng-model="username" ng-minlength="5" required>
        </label>
        <label class="item item-input"> <span class="input-label">Password</span>

            <input type="password" name="password" data-ng-model="password" ng-minlength="6" required>
        </label>
    </div>
            <button type="submit" ng-click="clear()">Clear</button>
</div>
angular.module('myApp', [])
    .controller('dummy', ['$scope', function ($scope) {

    $scope.clear = function () {
        $scope.username = "";
        $scope.password = "";
        console.log(username);
        console.log(password);
    };

}]);
<div ng-controller="MyCtrl">
    <label class="item item-input">
        <span class="input-label">Username</span>
        <input type="email" name="username" ng-model="username" ng-minlength="5" required>
    </label>
    <label class="item item-input">
        <span class="input-label">Password</span>
        <input type="password" name="password" ng-model="password" ng-minlength="6" required>
    </label>
    <button ng-click="clear()">Clear</button>
</div>
var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl', function($scope) {
    $scope.username = 'Foo';
    $scope.password = 'Bar';

    $scope.clear = function () {
        $scope.username = '';
        $scope.password = '';    
        console.log($scope.username);
        console.log($scope.password);   
    };
});
    <ion-content ng-controller="ExampleCtrl">
          <div class="list">
                <label class="item item-input">
                    <span class="input-label">Username</span>
                    <input type="email" name="username" ng-model="form.username" ng-minlength="5" required>
                </label>
                <label class="item item-input">
                    <span class="input-label">Password</span>
                    <input type="password" name="password" data-ng-model="form.password" ng-minlength="6" required>
                </label>
                <button class="button button-bar button-balanced" ng-click="submit()">Submit</button>
<button class="button button-bar button-balanced" ng-click="clear()">Clear</button>
            </div>
          </ion-content>
.controller('ExampleCtrl', ['$scope', function ($scope) {
  $scope.form = "";
  $scope.submit = function(){
  console.log($scope.form.username);
  console.log($scope.form.password);
  }
  $scope.clear = function(){
    $scope.form="";
  }

}])