【发布时间】:2018-09-25 17:49:18
【问题描述】:
我有一个包含值的数组,我提出一个请求,将信息发送到多选。
当我打开我的选择时,我预先选择了几个值。
我的问题是,如果我单击取消选中 boostrap 多选上的复选框,我想从我的数组中删除此信息。如果我单击复选框,我想将值放回数组中。
在我的代码中,我首先检查值是否在数组中,但与 boostrap 选择的交互不是我想要做的。
// that bring the information in boostrap multiselect
var vetornovo = ValueChecked();
// here i try to detect the change to check and unchecked but doesnt works
// all informations is selected: "selected" by default
$("#os-select-list").change(function() {
// i take the checkbox value.
var valueck = parseInt($("#os-select-list option:selected").text());
// if the information is in that i array when i click to unchecked then remove.
if (vetornovo.indexOf(valueck) > -1) {
index = $.inArray(valueck, vetornovo);
vetornovo.splice(index, 1);
console.log(vetornovo);
// when i click to selecte the value again i push and insert back to the array.
} else {
vetornovo.push(valueck);
console.log(vetornovo);
}
});
我想了解什么是错的,为什么当我点击复选框时不做并且有时会重复内容。
【问题讨论】:
标签: javascript jquery multi-select bootstrap-multiselect