gpt4 book ai didi

html - 单击更改按钮的颜色并使用javascript将其插入数组

转载 作者:行者123 更新时间:2023-11-28 08:32:15 25 4
gpt4 key购买 nike

我正在尝试更改按钮的颜色以查看该按钮是否被选中。当选择按钮时,按钮的值被插入数组。如果我再次单击选定按钮,则选定按钮将变为未选定状态,按钮的新颜色也将被删除,该按钮的值也将从数组中删除。我总共有 40 个按钮。我做了一个演示。这是我的链接

JSFiddle snippet

function ctrl($scope) {
$scope.tooth=[];
var count=0;
$scope.setTooth = function(event,code) {

if($scope.tooth.indexOf(code) > -1){
alert("hiii");
$scope.styleO = "styleOne";
$scope.tooth.splice($scope.tooth.indexOf(code), 1);
//$scope.tooth.push();
}else{
$scope.tooth[count]=code;
alert("hello");
$scope.styleT = "styleTwo";
}
}
$scope.setQuadrantsTeeth = function(quadarent){

}
}

提前致谢。

最佳答案

我将把数组的推送和拼接留给你。但就应用样式 1 和 2 而言,你为什么不这样做呢?

        $("button").click(function(){
if($(this).hasClass("styleOne")){
$(this).removeClass("styleOne");
$(this).addClass("styleTwo");
} else if($(this).hasClass("styleTwo")) {
$(this).removeClass("styleTwo");
} else if(!($(this).hasClass("styleTwo") || $(this).hasClass("styleOne"))){
$(this).addClass("styleOne");
}
});

关于html - 单击更改按钮的颜色并使用javascript将其插入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28211820/

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