【发布时间】:2021-05-25 11:20:40
【问题描述】:
这是我的模式,其中包括一些带有全选选项的复选框,请告诉我如何在我仅使用 jquery 而不是 localstorage 刷新页面后保持复选框处于选中状态:
<!--Modal-->
<div class="modal fade" id="invoiceOptions" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body text-justify">
<form class="form">
<div class="form-group">
<div class="input-group checkbox">
<label>
<input type="checkbox" name="select-all" id="checkAll"/>
Select All
</label>
<br>
<label>
<input type="checkbox" class="invoiceOption"/>
Item 1
</label>
<label>
<input type="checkbox" class="invoiceOption"/>
Item 2
</label>
<label>
<input type="checkbox" class="invoiceOption"/>
Item 3
</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="saveBtn" value="" data-dismiss="modal">
save
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!--/Modal-->
这是我的模态的 jquery 脚本:
<script>
$('#checkAll').click(function(event) {
if(this.checked) {
$('.invoiceOption').each(function() {
this.checked = true;
});
} else {
$('.invoiceOption').each(function() {
this.checked = false;
});
}
});
</script>
【问题讨论】:
标签: javascript html jquery css checkbox