【发布时间】:2019-04-13 02:17:18
【问题描述】:
我正在尝试将这些功能添加到我的订购单中
- 当 checkbox 被选中时,Qty dropdown 值将变为 1
- 当 checkbox 未选中时,Qty dropdown 值将变为 0
- 当 Qty dropdown 值设置为除 0 以外的任何值时 checkbox 将更改为选中
- 当 Qty dropdown 值设置为 0 时,checkbox 将取消选中
我已经完成了大部分工作,
但我无法让#4 工作 - 当下拉设置为 0 时复选框不会取消选中。
这里是代码codepen
$(document).ready(function() {
$(".product input:checkbox").change(function() {
if ($(this).is(":checked")) {
$(this).siblings("select").val(1);
} else {
$(this).siblings("select").val(0);
}
});
$(".product select").change(function() {
if ($(this).val != '0') {
$(this).siblings("input:checkbox").prop("checked", true);
}else{
$(this).siblings("input:checkbox").prop("checked", false);
}
});
});
【问题讨论】:
标签: jquery html css forms checkbox