当单击行的编辑按钮或删除按钮时,我想存储学生ID以及检查类型,即编辑或删除类型,然后使用它来更新数据库中的数据。目前我已经编写了html和jquery来检查按下相应按钮时的复选框。现在我陷入了如何将数据存储在数组中并将其向前传递的问题。数据应采用stdList(id = 1,check ='edit')的形式。
这是我的HTML
<div class="alert alert-danger" role="alert"></div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Checklist</th>
<th>Id</th>
<th>Student Name</th>
<th>Address</th>
<th>Phone</th>
<th>Class</th>
<th colspan="2">Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="checkbox" id="editCheck" class="editCheck" />
<input type="checkbox" id="deleteCheck" class="deleteCheck" />
</td>
<td>1</td>
<td>
<input type="text" class="form-control item" readonly="readonly" />
</td>
<td>
<input type="text" class="form-control item" readonly="readonly" />
</td>
<td>
<input type="text" class="form-control item" readonly="readonly" />
</td>
<td>12</td>
<td>
<button type="button" class="btn btn-info btn-xs" id="btn1">Edit</button>
</td>
<td>
<button type="button" class="btn btn-danger btn-xs" id="dbtn1">Delete</button>
</td>
</tr>
<tr>
<td>
<input type="checkbox" id="editCheck" class="btn2" />
<input type="checkbox" id="deleteCheck" />
</td>
<td>1</td>
<td>
<input type="text" class="form-control item" readonly="readonly" />
</td>
<td>
<input type="text" class="form-control item" readonly="readonly" />
</td>
<td>
<input type="text" class="form-control item" readonly="readonly" />
</td>
<td>12</td>
<td>
<button type="button" class="btn btn-info btn-xs" id="btn2">Edit</button>
</td>
<td>
<button type="button" class="btn btn-danger btn-xs" id="dbtn2">Delete</button>
</td>
</tr>
</tbody>
这是jquery
$('.btn.btn-info.btn-xs').click(function () {
var $tr = $(this).closest('tr')
$tr.find('input:checkbox').first().prop('checked', 'true');
$tr.find('input').removeAttr('readonly');
check($tr);
});
$('.btn.btn-danger.btn-xs').click(function () {
var $tr = $(this).closest('tr');
$tr.find('input:checkbox').last().prop('checked', 'true');
check($tr);
});
function check($tr) {
if (($tr.find('input:checkbox').first().is(":checked")) && ($tr.find('input:checkbox').last().is(":checked"))) {
$('.alert.alert-danger').append('<p>You can not edit and update the field at once</p>');
}
}
答案 0 :(得分:0)
从提到的问题中,您需要保存学生的详细信息和调用的操作。因此,下面的方法可以用来做同样的事情。
Create a object like below . var item=new Object(); item.studentId = "student id"; item.Action="edit/delete action" Create an array to save this var studentInfo = new Array(); then Add items to array, studentInfo.push(item); Use the Array as required in you code