gpt4 book ai didi

javascript - 如何在不同的复选框 Angular 之间切换

转载 作者:行者123 更新时间:2023-11-30 09:44:25 26 4
gpt4 key购买 nike

我有四个复选框,每次单击复选框都会启动不同的功能。选中一个复选框,所有其他复选框都应取消选中。我有以下代码,但问题是如果不先手动删除复选标记然后选择另一个复选标记,我就无法在检查之间切换。我的代码:

  $scope.checkbox = function(key){
if($scope.checkbox1 === true){
$scope.checkbox2 = false
$scope.checkbox3 = false
$scope.checkbox4 = false
$scope.checkboxValue = 'checkbox one was clicked'
callfunctionOne()
} else if($scope.checkbox2 === true){
$scope.checkbox1 = false
$scope.checkbox3 = false
$scope.checkbox4 = false
$scope.checkboxValue = 'checkbox two was clicked'
callfunctiontwo()
} else if($scope.checkbox3 === true){
$scope.checkbox1 = false
$scope.checkbox2 = false
$scope.checkbox4 = false
$scope.checkboxValue = 'checkbox three was clicked'
callfunctionthree()
} else if($scope.checkbox4 === true){
$scope.checkbox1 = false
$scope.checkbox2 = false
$scope.checkbox3 = false
$scope.checkboxValue = 'checkbox Four was clicked'

callfunctionFour()
}

}

Plunker

最佳答案

  $scope.checkbox = function(key){
$scope.checkbox1 = false
$scope.checkbox2 = false
$scope.checkbox3 = false
$scope.checkbox4 = false
$scope[key] = true;
$scope.checkboxValue = 'checkbox '+key+' was clicked'
}

您应该考虑使用单选按钮,但此代码允许您做您想做的事。

关于javascript - 如何在不同的复选框 Angular 之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39508881/

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