빈 sendStatus[]
이 있습니다. 기본적으로 나는 배열에 사용자가 확인란을 클릭하는 동안 존재 여부를 값을 확인입니다. 그게 없다면 나는 사용자가 체크 박스를 다시 클릭 할 경우 "add + this.value"값을 더하는 것 뿐이다.jquery 필터가 올바른 결과를 제공하지 않습니다.
sendStatus[]
에 "add + this.value"가 있는지 검사 할 것이다. 나는 그것을 제거하고 새 값을 "remove + this.value"로 추가하므로 각 체크 박스에서 "add + this.value"또는 "remove + this.value"값만 가져옵니다.
var sendStatus = [];
var clearValues = function(newVal){
console.log("calling",newVal);
}
$("form").on("click", ":checkbox", function(e){
var el = $(this),parentClass = $(this).parent().hasClass("green"),label = $(this).parent();
if(!parentClass){
label.addClass("green");
sendStatus = $.grep(sendStatus, function(value) {
return value != "remove" + el.val();
});
if ($.inArray("add" + el.val(), sendStatus) === -1) {
sendStatus.push("add" + el.val());
}
}else{
label.toggleClass("red");
sendStatus = $.grep(sendStatus, function(value) {
return value != "add" + el.val();
});
if ($.inArray("remove" + el.val(), sendStatus) === -1){
sendStatus.push("remove" + el.val());
}
}
console.log(sendStatus);
})
사람이 사전에 .. 덕분에 내 기능을 단순화하고 내가 직면하고있는 무슨 문제를 강조 표시합니다.
구조에 대한 HTML 예제를 제공해 주시겠습니까? : 체크 박스가 '[type = "checkbox"]'가 아니어야합니다. – Edorka