我正在使用不错的选择下拉菜单,其中有多个选项可以选中或取消选中。
这里的问题是我可以选中或取消选中所有选项,并且需要在页面加载时检查特定复选框。
我尝试了很多,还添加了这些行。
$('#Person').val("1").prop('checked', true);
$("#Person").niceSelect("update");
执行此操作时在控制台中显示“已检查:true”,但更改不会反映在页面上。
为了取消选中我正在使用下面的代码的所有复选框。
$(".styled-checkbox").prop('checked', false);
<div class="box"><div class="nice-select wide" tabindex="0" id="Person"></div></div>
$('#Person').val("1").prop('checked', true);
$("input[type=checkbox][value=" + xy + "]").attr("checked", "true");
$("#Person").val(xy);
$('#Person').val(xy).prop('selected', true);
$('#Person').val(xy);
$('#Person').multiSelect('select', [2, 1]);
$("#Person option[value='2']").prop('selected', true);
$("#Person option[value='2']").attr("selected", true);
如何使用其值设置选中或未选中的复选框?