我正在创建一个用户管理页面,其中我有一个表,表的第一列是复选框,第一列是一个全选框。我想一个按钮采取的值或值,如果复选框被勾选,并发送后请求。我写的代码,但它总是并且只发送表中的第一个值,无论任何框是否票。
HTML表格如下:
<table id="userList" class="table table-bordered table-striped">
<thead>
<tr>
<th><input type="checkbox" onClick="toggle(this)" /></th>
<th>Name</th>
<th>Credential</th>
<th>Email</th>
<th>Start Date</th>
<th>End Date</th>
<th>Status</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
</table>
字符串
第一列是从php代码填充的复选框
第一个月
复选框选择所有脚本
function toggle(source) {
checkboxes = document.getElementsByName('check');
for(var i=0, n=checkboxes.length;i<10;i++) {
checkboxes[i].checked = source.checked;
}
}
型
我想做一个按钮,以获取userid值,并提交他们在发布请求,以禁用多个用户在同一时间php代码工作正常,但我无法使jquery部分工作:
$(document).on('click', '.deactivateUsers', function(){
var userid = $('#cbuserid').val();
var action = "userDeactivate";
if(confirm("Are you sure you want to deactivate this user?")) {
$.ajax({
url:"action.php",
method:"POST",
data:{userid:userid, action:action},
success:function(data) {
window.location.reload();
}
})
} else {
return false;
}
});
型
无论是否勾选了任何复选框,这段代码总是取cbuserid的第一个值。
1条答案
按热度按时间iqih9akk1#
我建议您使用按钮的onclick属性并添加
字符串
类似这样的东西::
型
或无数据
型
您可以使用数据属性的方法
型