當提交後刷新頁面時,我的複選框爲空。我想讓他們檢查。我怎麼能在jQuery中做到這一點?Jquery複選框在提交時取消選中
這是我的jQuery代碼。
$(document).ready(function() {
$(':checkbox.selectall').on('click', function() {
$(':checkbox[id="' + $(this).data('checkbox-name') + '"]').prop("checked", $(this).prop("checked"));
$("#frm1").submit();
});
$(':checkbox.checkme').on('click', function() {
var _selectall = $(this).prop("checked");
if (_selectall) {
$(':checkbox[name="' + $(this).attr('name') + '"]').each(function (i) {
_selectall = $(this).prop("checked");
return _selectall;
});
}
$(':checkbox[name="' + $(this).data('select-all') + '"]').prop("checked", _selectall);
$("#frm1").submit();
});
});
我的HTML如下:...
<input type='checkbox' id='selectall' name='sa_subcatinput[]' value='$row[id]'
data-checkbox-name='$row[id]' class='selectall'/></label></a></li>
<input type='checkbox' name='subcatinput[]' value='$test[id]' id='$test[category]'
class='checkme' data-select-all='sa_subcatinput[]'/>
如果它是一個php頁面,並且您將表單提交到同一頁面,只需使用發佈數據來設置創建它們的複選框的值。 – Archer