取消弹出消息的按钮,然后删除不运行

发布于 2025-02-12 06:07:42 字数 426 浏览 2 评论 0原文

我遇到的问题,当确认消息出现时,我单击“取消”按钮,数据也将被删除。有人可以建议需要修复的地方吗?以下是代码。

echo "<a onClick='myFunction()' href='./delete.php?userID=".$row['userID'] ."'><button>Delete</button></a>";

    <script> 
        function myFunction() {
            $r = confirm("OK to delete?");
            if ($r == false) {
                return false;
                } 
        }
    </script>

I've facing problem where, when the confirmation message appear, I click the cancel button, the data will be also deleted. Can someone suggest where need to be fix? Below is the code.

echo "<a onClick='myFunction()' href='./delete.php?userID=".$row['userID'] ."'><button>Delete</button></a>";

    <script> 
        function myFunction() {
            $r = confirm("OK to delete?");
            if ($r == false) {
                return false;
                } 
        }
    </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情栀口红 2025-02-19 06:07:48

使用event.preventdefault()单击“取消”时,必须防止锚标记事件。

例子

<a onClick="myFunction()" href="https://google.com">Delete
<script>
   function myFunction() { 
      let r = confirm("OK to delete?"); 
      
      if (r == false) { 
        // It will prevent visit to 'https://google.com'
        return event.preventDefault();
      } 
   }
    
</script>

The anchor tag event has to be prevented when the 'Cancel' is clicked with event.preventDefault().

Example

<a onClick="myFunction()" href="https://google.com">Delete
<script>
   function myFunction() { 
      let r = confirm("OK to delete?"); 
      
      if (r == false) { 
        // It will prevent visit to 'https://google.com'
        return event.preventDefault();
      } 
   }
    
</script>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文