douxiong3234 2013-01-07 20:10
浏览 33
已采纳

向按钮单击添加警报

I have been trying to add a alert to my button which updates a users details in a database.

I have tried adding a onclick method directly to the button and using functions but it doesn;t seem to work.

My button is;

<input type="submit" id="profileclick" value="Update" class="button-link"/>

And I am submitting the form by: (if it is important)

<form id="profile" method="post" action="../script/updateUserDetails.php">

One of the ways I tried was

$('#profileclick').click(function(){
 alert('Your details have been updated');
 $('#profile').submit();
});

In all instances the details update but I do not receive a alert.

  • 写回答

2条回答 默认 最新

  • duanlu7680 2013-01-07 20:12
    关注
    $('#profileclick').click(function(){    
         alert('Your details have been updated');
         $('#profile').submit();
    });
    
    
    $('#profile').submit(function( e ){
             e.preventDefault();
    
             // ........ AJAX SUBMIT FORM
    });
    

    Or simply add a delay before you submit using setTimeout ...

    $('#profileclick').click(function(){    
         alert('Your details have been updated');
         setTimeout(function(){
                 $('#profile').submit();
         }, 2000);        
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?