2015-07-20 84 views
0

我有一个dropdowncheckbox和hiddenfield值。隐藏的字段值是1,3,4,5。所以我想设置dropdowncheckbox在jQuery中回发后检查相关的hiddenfield值。我该怎么做?如何设置刷新后选中的复选框项目?

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

cookie或查询字符串传递它拆开从那个服务器端语言将需要。 –

+0

你使用更新面板? –

+0

在会话中存储您的所需值,然后在整个应用程序中调用该会话值,直到该会话值得到清除或更改。 – Shirish

回答

0

您可以使用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" /> 

fiddle

参考文献:

Window.localStorage

+0

实际上,我具有hiddenfield.But中的值,但我希望这些隐藏的字段值回发后选中复选框。 – user3737149

+0

但回发后隐藏的字段会丢失它们的值,或者您从数据库中检索它们? –

+0

但当我在控制台调试JavaScript他们检索hiddenfiled values.But在$ .each(功能()。请看看我的上述代码,如果你有任何想法,请告诉我更正一些问题。 – user3737149