angularjs使用ng-change实现checkbox变化触发事件时,利用ng-checked实现选中却不触发ng-change事件,只有手动点击时才能触发,大致意思就是只有直接点
var uid_list = [];
$scope.add = function (item_checked,uid) {
var uid = parseInt(uid);
if(item_checked){
uid_list.push(uid);
}
if(!item_checked){
var index = uid_list.indexOf(uid);
uid_list.splice(index,1);
}
console.log(uid_list);
};
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
ngChange
如果你全选,直接处理data数据取出所有ID就可以了吧,不用调用add()去添加ID吧。ngChange
Evaluate the given expression when the user changes the input. The expression is evaluated immediately, unlike the JavaScript onchange event which only triggers at the end of a change (usually, when the user leaves the form element or presses the return key).