我从数组中的复选框发送值有问题。我的意思是,按下按钮添加后,我可以动态生成表,在表中克隆行。您知道如何在克隆行之后增加值吗?或者您知道发送复选框状态的更好的主意?
<input type = "checkbox" class = "checkbox inline" name = "bs[]" id = "checkbs" value = "1">
JS代码:
$(document).ready(function() {
//Disable the Remove Button
var rowCount = $('table >tbody:last >tr').length;
if(rowCount == 1) {
document.getElementsByClassName('btn-remove')[0].disabled = true;
}
$(document).on('click', '.btn-add', function(e) {
e.preventDefault();
var controlForm = $('table');
var currentEntry = $('table>tbody>tr:last');
var newEntry = $(currentEntry.clone()).appendTo(controlForm);
newEntry.find('input').val(''); //Remove the Data - as it is cloned from the above
//Add the button
var rowCount = $('table >tbody:last >tr').length;
if(rowCount > 1) {
var removeButtons = document.getElementsByClassName('btn-remove');
for(var i = 0; i < removeButtons.length; i++) {
removeButtons.item(i).disabled = false;
$('#checkbs').val(function(i, oldval)
{
return ++oldval;
});
}
}
}).on('click', '.btn-remove', function(e) {
$(this).parents('tr:first').remove();
//Disable the Remove Button
var rowCount = $('table >tbody:last >tr').length;
if(rowCount == 1) {
document.getElementsByClassName('btn-remove')[0].disabled = true;
}
e.preventDefault();
return false;
});
});