如何獲取選中的複選框id到一個隱藏的變量?獲取html複選框列表選中的值隱藏字段
我收到此錯誤。
SyntaxError: unterminated string literal
var test = $('input[name=\'data-grid_c0[]\').val();
數據grid_c0是複選框陣列的名稱。
<input type="checkbox" name="data-grid_c0[]" id="data-grid_c0_1" value="1">
<input type="checkbox" name="data-grid_c0[]" id="data-grid_c0_2" value="1">
<input type="checkbox" name="data-grid_c0[]" id="data-grid_c0_3" value="1">
下面是我寫的jQuery代碼。
$('#deleteall-button').click(function() {
var atLeastOneIsChecked = $('input[name=\"data-grid_c0[]\"]:checked').length > 0;
var test = $('input[name=\'data-grid_c0[]\').val();
alert(test);
if (!atLeastOneIsChecked)
{
alert('Please select atleast one record to delete');
}
else if (window.confirm('Are you sure you want to delete the records?'))
{
document.getElementById('search-form').action = 'index.php?r=device/bulkDelete';
document.getElementById('search-form').submit();
}
});
我想數據grid_c0的價值被分配到selectedDevices隱藏字段。
<form action="hotelSearch/hotelSearch" method="post"><input id="selectedDevices" type="hidden" value="" name="selectedDevices" /><a id="deleteall-button" class="btn btn-primary">Bulk Delete</a></form>
,使用PHP,我將能夠處理它如下,並刪除,
//check-boxes
if (isset($_POST['selectedDevices'])) { //data-grid_c0
$del_camps = $_POST['selectedDevices']; //data-grid_c0
$model_camp = new Device;
foreach ($del_camps as $_camp_id) {
$model_camp->deleteByPk($_camp_id);
}
}
你爲什麼不只是張貼自己他們將得到公佈爲CSV反正複選框 – 2014-10-10 06:39:11