gpt4 book ai didi

javascript - 提交后angularjs清除输入字段

转载 作者:行者123 更新时间:2023-11-27 23:16:17 24 4
gpt4 key购买 nike

尝试在单击按钮后清除输入字段并使用 Angular 保存帖子,但它不起作用。这是一个简单的代码

<!--html-->
<input type="text" ng-model="addField"/>
<button type="button" ng-click="addPost(item)">add</button>

/*script*/
$scope.addField = '';
function addPost(item) {
/*code for adding*/
$scope.addField = "";
}

最佳答案

使用对象代替字符串,试试这个

<!--html-->
<input type="text" ng-model="form.addField"/>
<button type="button" ng-click="addPost(item)">add</button>

/*script*/
$scope.form = {};
$scope.addPost = function(item) {
/*code for adding*/
$scope.form = {};
}

关于javascript - 提交后angularjs清除输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43015724/

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