I am using boostrap multi select drop-down. On pageload i have two checkboxes checked in the drop-down list. I have added data-attributes for option values. On clicking a checkbox, if data-attribute value is greater than zero i need to kepp the checkbox checked. I have used jquery method to check a checkbox
$(".checkbox").prop("checked",true)
but when i check the number of checkboxes checked using $(".checkbox option:selected)
it is not including the checkbox which i checked progrmatically. Can any one help me.
HTML generated for bootstrap multiselect drop-down:
<select class="form-control" id="comm" multiple="multiple" name="comm[]" style="display: none;">
<option value="abc" data-id="0">abc</option>
<option value="xyz" data-id="0">xyz</option>
<option value="pqr" data-id="0">pqr</option>
<option value="mno" selected="selected" data-id="24">mno</option>
</select>
<div class="btn-group">
<button type="button" class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" title="None selected">xyz</button>
<ul class="multiselect-container dropdown-menu">
<li><a href="javascript:void(0);">
<label class="checkbox"><input type="checkbox" value="abc">abc</label>
</a>
</li>
<li><a href="javascript:void(0);">
<label class="checkbox"><input type="checkbox" value="xyz"> xyz</label>
</a>
</li>
<li><a href="javascript:void(0);">
<label class="checkbox"><input type="checkbox" value="pqr"> pqr</label>
</a>
</li>
<li class=""><a href="javascript:void(0);">
<label class="checkbox"><input type="checkbox" value="mno"> mno</label>
</a>
</li>
</ul>
</div>
尝试这个
$(".checkbox:checked")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.