使用jAlert进行确认删除警报

时间:2014-11-14 16:34:54

标签: javascript jquery html

如果在网页Form上点击确定,我会执行alert操作的例程:

SCRIPT

<script language="JavaScript" type="text/javascript">
function checkDelete(){
return confirm('Are you sure you want to delete this record?');
}
</script>

HTML

<form action="https://website/delUser.php" method="Post">
<input value="Delete" type="submit" onclick="return checkDelete()" class="submitButton">
</form>

为了使警报更具吸引力,我尝试使用jAlert

JALERT SCRIPT

<script type="text/javascript">
$(document).ready( function()
{
  $("#confirm_button").click( function()
  {
    jConfirm('Delete this user?', 'Title', function(result) 
    {
     jAlert('Pressed: ' + result, 'Results'); //This displays the result as an alert - true or false
    });
  });
});
</script>

显示新警报,但我不确定如何更改HTML,以便仅在警报返回true时才运行Form操作。

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

HTML

<form name="test_form" action="action.php">
    <input type="button" value="Delete" class="submitButton" id="confirm_button">
</form>

JS

$("#confirm_button").click( function()
{
    jConfirm('Delete this user?', 'Title', function(result) 
    {
        if(result){
            // FORM ACTION HERE
            test_form.submit();
        }
    });
});