js中数组的添加和移除

时间:2020-09-06 19:35:47   收藏:0   阅读:66

   1.引入js文件

<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>

2.HTML中代码的书写
<td><input  type="checkbox" ng-click="updateSelection($event,entity.id)"></td>
$event 代表该行是否被选中
entity.id为自己需要传入的值


3.js代码书写
//定义一个数组
$scope.selectIds=[];
$scope.updateSelection=function($event,id){
if($event.target.checked){
//往数组中加入一个元素
$scope.selectIds.push(id);
}else{
//删除数组中一个元素
var i=$event.selectIds.indexOf(id);
$scope.selectIds.splice(i,1);
}
}
备注:先定义一个数组 selectIds ,如果选中,则往数组中添加一个元素,否则,移除一个元素。


原文:https://www.cnblogs.com/xiaofengshan/p/13622052.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!