js,弹出甜蜜提醒

问题描述 投票:0回答:1

请帮我解决问题。我正在尝试制作一个带有甜蜜警报的弹出窗口。当您提交按钮时,弹出窗口应该显示结果! ($("#input name").val(data);) 并在 Sweet Alert 部分中应该是 php 脚本的帖子!如果你能帮助我那就太好了。

<form action="" method="post" id="formx" onsubmit="submitForm(this, event)"
function submitForm(form, event ) {
         event.preventDefault()
         Swal.fire({
          title: 'Are you sure?',
          text: 'text text text',
          icon: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: 'Yes, Send!'
        }).then((result) => {
          //console.log(result) 
          if (result.isConfirmed) {
            form.submit();
          }
        })
        return false
}
javascript popup alert
1个回答
0
投票

更新您的代码

对于 HTML

<form action="path_to_your_php_script.php" method="post" id="formx" onsubmit="submitForm(event)">
    <input type="text" name="inputName" id="inputName" placeholder="Enter something...">
    <button type="submit">Submit</button>
</form>

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.all.min.js"></script>

和JS

function submitForm(event) {
    event.preventDefault();
    const inputValue = document.getElementById('inputName').value;

    Swal.fire({
        title: 'Are you sure?',
        text: `You entered: ${inputValue}`,
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, Send!'
    }).then((result) => {
        if (result.isConfirmed) {
            event.target.submit();
        }
    });
}
© www.soinside.com 2019 - 2024. All rights reserved.