无法选中 nice select 多个下拉列表的复选框?

Unable to check checkbox of nice select multiple dropdown?

我正在使用不错的 select 下拉菜单,它有多个选项,我可以选中或取消选中。

这里的问题是我可以选中或取消选中所有选项,需要的是在加载页面时选中特定的复选框。

我尝试了很多,也添加了这些行。

$('#Person').val("1").prop('checked', true);          
$("#Person").niceSelect("update");

执行此操作时会在控制台中显示 "checked: 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);

如何使用其值设置选中或未选中复选框?

您使用了错误的属性 select 下拉菜单的值,试试这个

<select id="abc">
  <option value="">Select</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>


//abc id of your select and i want to select option with value 2
<script>
  $('#abc option[value="2"]').prop("selected", "true");
  $("select").niceSelect("update");
</script>

我通过从下面的代码中删除单词 "checked" 来解决这个问题。 它用于在其他地方加载时默认选中所有复选框。 如果我们要删除这个词,那么我们可以选中或取消选中特定选项。

'<li> <input class="styled-checkbox" checked id="styled-checkbox-' + i + '" type="checkbox" value="' + data[i][dataValueField] + '"><label for="styled-checkbox-' + i + '">' + data[i][dataTextField] + '</label></li>';