html 表单提交前显示提示2

rvpgvaaj  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(173)

我有一个注册帐户的代码。我希望在表单提交和页面重新加载之前显示成功警报,或者在表单成功提交后弹出成功警报。
我尝试了这段代码,我它只是提交表单并重新加载页面,但警报没有出现。
`

  1. if ($password == $cpassword) {
  2. $query1 = mysqli_query($connections, $query);
  3. if ($query1){
  4. echo "
  5. <script type='text/javascript'>setTimeout(function () {
  6. Swal.fire({
  7. title: 'Success!',
  8. icon: 'success',
  9. text: 'Account registered!',
  10. allowOutsideClick: true,
  11. allowEscapeKey: true,
  12. allowEnterKey: false,
  13. showConfirmButton: false,
  14. });
  15. },100) </script>";
  16. }
  17. echo "<script>window.location.href='accounts.php'</script>";
  18. }

`
我还尝试了另一个代码,警报工作,但表单提交两次

  1. if ($password == $cpassword) {
  2. mysqli_query($connections, $query);
  3. echo "
  4. <script type='text/javascript'>setTimeout(function () {
  5. Swal.fire({
  6. title: 'Success!',
  7. icon: 'success',
  8. text: 'Account registered!',
  9. allowOutsideClick: true,
  10. allowEscapeKey: true,
  11. allowEnterKey: false,
  12. showConfirmButton: false,
  13. });
  14. },100)
  15. window.setTimeout(function(){
  16. if(!window.location.hash) {
  17. window.location = window.location + '#loaded';
  18. window.location.reload();
  19. }
  20. } ,100);
  21. </script>";
  22. }
efzxgjgh

efzxgjgh1#

在触发甜蜜提醒信息后,您缺少该功能。您可以按以下方式使用:

  1. $(document).on('click', '.delete_trigger_btn', function () {
  2. let redirect_url = $(this).attr('data-href');
  3. Swal.fire({
  4. title: 'Success!',
  5. icon: 'success',
  6. text: 'Account registered!',
  7. allowOutsideClick: true,
  8. allowEscapeKey: true,
  9. allowEnterKey: false,
  10. showConfirmButton: false,
  11. }).then(function (t) {
  12. if (t.value == true) {
  13. window.location.href = redirect_url;
  14. }
  15. });
  16. });

您可以直接传递URL,也可以通过设置隐藏属性保留在输入字段中。
我希望这能有所帮助,这就是你正在寻找的。

展开查看全部

相关问题