我有这个:
var category = "3%2C16%2C6%2C10%2C1%2C19";
在女巫中,类别ID是3 16 6 10 1 19
和%2C
是类别之间的空格。
我想要的是这里:
if (document.getElementById("3").checked = false) {
category = "16%2C6%2C10%2C1%2C19";
}
else {
category = "3%2C16%2C6%2C10%2C1%2C19";
}
我想为我拥有的所有复选框创建此复选框,但是您不能取消选中所有复选框,因为服务器不会向您发送任何数据。
这是用于过滤结果
使用数组比较容易,然后在需要时将其转换为此字符串表示形式。
var categories = [];
$('#category-form input').change(function () {
var id = $(this).attr('data-id'),
index = categories.indexOf(id);
if (this.checked && index === -1) {
categories.push(id);
} else if (!this.checked && index !== -1) {
categories.splice(index, 1);
}
});
您可以在这个小提琴中看到我的工作代码。(具有多个复选框,字符串表示形式和至少一个复选框)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句