简体   繁体   English

单击按钮时取消选中复选框

[英]Uncheck the checkbox when clicked On Button

I have checkbox list and I want to clear all checked data after Clear button.我有复选框列表,我想在清除按钮后清除所有选中的数据。 The data is fetch from json for checkboxes.数据是从 json 中获取的复选框。

HTML: HTML:

<div ng-repeat="data in array" >
    <label class="Form-label--tick">
        <input type="checkbox" id="statusid"  value="{{data.id}}" class="Form-label-checkbox" ng-click="print(data.id)">
        <span class="Form-label-text" id="statusname" value="{{data.name}}"> {{data.name}}</span>
    </label>
</div>

JavaScript: JavaScript:

  $scope.clearFilters = function() {
     document.getElementById('statusid').value="";
     document.getElementById('statusname').value="";
  };

clearFilters() is called when Clear Button is clicked.But I am not able clear the checked boxes.It remains checked even after the clear button. clearFilters()在点击清除按钮时被调用。但我无法清除选中的框。即使在清除按钮之后它仍然保持选中状态。

This code is not angular.这段代码不是有角度的。 Don't try to modify any DOM elements directly, but use the $scope variables to change their value.不要尝试直接修改任何 DOM 元素,而是使用 $scope 变量来更改它们的值。

In angular the checkbox return true or false so to uncheck a checkbox just change it's value to false.在 angular 中,复选框返回 true 或 false,因此要取消选中复选框,只需将其值更改为 false。

so your code should look like this:所以你的代码应该是这样的:

  $scope.clearFilters = function() {
     $scope.data.id = false;
     $scope.data.name = ""; 
  };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM