我尝试在onclick操作后重定向用户,但以下代码中的userid始终保持与用户在表中选择的相同。 也许我在这里错过了一些东西......
<td>
<?php if ($memberinfo['UserIsChecked'] == 1){ ?>
<button class="btn btn-xs btn-icon btn-default"> <i class="fa fa-times"></i> </button>
<?php } else { ?>
<a href="#"><p onclick="go()">Approve/Refuse <?php echo($memberinfo['UserId']) ;?></p></a>
<script>
var userid='<?php echo $userid;?>';
function go(){
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Validate user',
cancelButtonText: 'Refuse request',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger m-l-10',
buttonsStyling: false
}).then(function () {
swal(
'User validated!',
'The user has been notified.',
'success',
).then(function(){
window.location = 'scripts/process-validate-user.php?userid='+ userid +' ' ;
})
}, function (dismiss) {
// dismiss can be 'cancel', 'overlay',
// 'close', and 'timer'
if (dismiss === 'cancel') {
swal(
'User refused',
'The user has been notified.',
'error'
)
}
})
}
</script>
<?php } ?>
</td>
答案 0 :(得分:0)
尝试添加x-userid =&#34;&#34;属性锚定标签,你绑定go()函数。然后在go函数中将按如下方式开始:
function go(event) {
var userid = event.target.getAttribute('x-userid');
...
}
答案 1 :(得分:0)
如果这些是表格行,那么您只需在<div>
之后添加隐藏的<tr>
,如下所示:
<td>
<?php if ($memberinfo['UserIsChecked'] == 1){ ?>
<button class="btn btn-xs btn-icon btn-default"> <i class="fa fa-times"></i> </button>
<?php } else { ?>
<span style="display:none" class="user-id"><?php echo($memberinfo['UserId']) ;?></span>
<a href="#"><p onclick="go()">Approve/Refuse <?php echo($memberinfo['UserId']) ;?></p></a>
然后,在JavaScript代码中,相对于用户的点击,通过JavaScript或jQuery获取此<span>
文本。