在我的管理面板中,我通过点击链接使用Jquery / Ajax编辑用户详细信息。它成功运行但我想在请求发送到服务器之前显示确认对话框/弹出框。如果是,则我的功能(myfunc1)将执行,否则它将关闭。我目前的代码看起来像这样。
<td width="70"><a href="#" onClick="myfunc1('<?php echo $uid;?>') "><input type="button" value="Edit Details" class="button" /></a></td>
function myfunc1(id) {
id = id;
$.ajax({
url: 'edit_user_details.php',
type: 'post',
data: {
'id': id
},
success: function (response) {
//$('#edit_user_result').html(response);
$('#sent_password_result' + id).html(response);
setTimeout(function () {
$('input[type=submit]').attr('disabled', false);
window.location.href = "users.php";
}, 5000);
}
});
}
如何使用jquery / Javascript执行此操作?谢谢您的帮助。
答案 0 :(得分:4)
您可以致电confirm()
function myfunc1(id) {
if (confirm("OK to submit?")) {
$.ajax({
url: 'edit_user_details.php',
type: 'post',
data: {'id' : id},
success: function(response) {
//$('#edit_user_result').html(response);
$('#sent_password_result'+id).html(response);
setTimeout(function() {
$('input[type=submit]').attr('disabled', false);
window.location.href = "users.php";
}, 5000 );
}
});
}
}
或者您可以在onclick
:
onclick="if (confirm('OK to submit?')) { myfunc1('<?php echo $uid;?>'); } "