gpt4 book ai didi

javascript - 清除按钮angularjs

转载 作者:行者123 更新时间:2023-11-30 12:16:40 25 4
gpt4 key购买 nike

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

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>

Javascript

$scope.submit = function(username) {
console.log("Thanks " + username);
};

$scope.submit = function(password) {
console.log("Thanks " + password);
};

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

最佳答案

这是一个有效的 JSFiddle

HTML:

<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>

JS:

angular.module('myApp', [])
.controller('dummy', ['$scope', function ($scope) {

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

}]);

关于javascript - 清除按钮angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32266133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com