我有一个dropdowncheckbox和hiddenfield值。隐藏字段值是1,3,4,5。所以我想设置dropdowncheckbox在jquery中回发后检查相关的隐藏字段值。我该怎么做?< / p>
$(document).ready(function() {
var Statushdn = document.getElementById('<%= hdnSubCategoryId.ClientID%>').value;
var str_array = Statushdn.split(',');
var summar;
$.each($('#ContentPlaceHolder1_ddcbProductStockSubCategory_dv input[type=checkbox]:not(:checked)'), function() {
summar = $(this).val();
for (var i = 0; i < str_array.length; i++) {
if (str_array[i] == summar)
$(this).attr('checked', 'checked');
}
});
});
答案 0 :(得分:1)
您可以使用localstorage来保留复选框中的值,如:
$(':checkbox').on('change', function () {
//set the check value of checkbox
localStorage.setItem(this.id, this.checked);
});
$(':checkbox').each(function () {
//retrieve the checked value from the checkboxes and 'convert' it to bool
var status = localStorage.getItem(this.id) === "false" ? false : true;
$(this).prop("checked", status);
});
<input type="checkbox" id="chk1" />
<input type="checkbox" id="chk2" />
<input type="checkbox" id="chk3" />
<input type="checkbox" id="chk4" />
参考文献: