无法选中好选择多个下拉列表的复选框?

问题描述 投票:0回答:2

我使用精选的选择下拉列表,它有多个选项,我可以检查或取消选中。

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

我尝试了很多,并添加了这些线。

$('#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);

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

jquery dropdown nice
2个回答
0
投票

您使用错误的道具来选择下拉列表中的值,请尝试此操作

<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>

0
投票

我通过从下面的代码中删除单词“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>';
© www.soinside.com 2019 - 2024. All rights reserved.