使用 PHP/MYSQL 删除前 JavaScript 确认

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16121538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:32:32  来源:igfitidea点击:

JavaScript Confirm before deletion with PHP/MYSQL

javascriptphpmysqlconfirm

提问by bingwa

I have tried a number of examples here but I can get my code to actually show a popup window before deletion. The code I use can be found here:

我在这里尝试了许多示例,但我可以让我的代码在删除之前实际显示一个弹出窗口。我使用的代码可以在这里找到:

echo "<td><button class='btn'><a href=\"deleteuserExecute2.php?login=" .$login. "\" onClick=\"return confirm(\'Delete this Account?\')\"; >DELETE ACCOUNT </a></button></td>";

echo "<td><button class='btn'><a href=\"deleteuserExecute2.php?login=" .$login. "\" onClick=\"return confirm(\'Delete this Account?\')\"; >DELETE ACCOUNT </a></button></td>";

http://jsfiddle.net/mpogoro/EGfcY/

http://jsfiddle.net/mpogoro/EGfcY/

回答by Samuel Cook

You just need to use the onclickmethod for your link or button:

您只需要使用onclick链接或按钮的方法:

<a href="DELETE_PAGE" onClick="return confirm('Delete This account?')">Delete Account</a>

回答by Richard

  <script type="text/javascript">
      function ConfirmDelete()
      {
            if (confirm("Delete Account?"))
                 location.href='linktoaccountdeletion';
      }
  </script>


  echo '<input type="button" onclick="ConfirmDelete()" value="DELETE ACCOUNT">';

回答by echo_Me

try this

尝试这个

 <form action="url/to/delation_page" onSubmit="return confirm('are you sure?')">

</form>

回答by Fahim Parkar

Just say

说啊

onclick="return confirm('Are you sure you want to delete?')"
         ^^^^^^ --> this is very important step...

回答by LOKESH

javascript confirmation

javascript确认

function doConfirm(id)
        {

            var ok = confirm("Are you sure to Delete?")
            if (ok)
            {

                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }

                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                    {
                         window.location = "create_dealer.php";  // self page
                    }
                }

                xmlhttp.open("GET", "delete_dealer.php?id=" + id);
                xmlhttp.send();
            }
        }

button for delete

删除按钮

<input type="button" onclick="doConfirm();"/>

回答by Raj the Starter

if u use on-click the data will be deleted but to view result u have to refresh the page manually instead use onSubmit="return confirm('are you sure?')"

如果你使用点击数据将被删除但要查看结果你必须手动刷新页面而不是使用 onSubmit="return confirm('are you sure?')"

think it helps !

觉得有帮助!