gpt4 book ai didi

angularjs - 如何在 Angular JS 中获取复选框数组?

转载 作者:行者123 更新时间:2023-12-03 08:24:16 25 4
gpt4 key购买 nike

我在 HTML 中有一些复选框:

<input type="checkbox" name="type[]" value="3">
<input type="checkbox" name="type[]" value="4">
<input type="checkbox" name="type[]" value="5">

如何在 Angular JS 中获取所有选定的值?

我尝试为搜索输入添加:ng-model="type[]"

最佳答案

试试这个:

<div ng-controller="MyCheckbox" 
ng-init="checkboxes = {1: true, 2: false, 3: true, 4: false}">
<input type="checkbox" ng-model="checkboxes.1">1
<input type="checkbox" ng-model="checkboxes.2">2
<input type="checkbox" ng-model="checkboxes.3">3
<input type="checkbox" ng-model="checkboxes.4">4
<br>{{checkboxes}}
</div>

JSFIDDLE DEMO

关于angularjs - 如何在 Angular JS 中获取复选框数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29748115/

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