Javascript 确认不起作用

Javascript Confirm not working

本文关键字:不起作用 确认 Javascript      更新时间:2023-09-26
echo "<td><a onclick='"confirm('Are you sure you want to permanently delete this post?');'" href='posts.php?id=".$res['id']."'>view</a></td>";

用PHP生成,确认没有弹出。我做错了什么?谢谢你的关注。

使用

onclick="return confirm('Are you sure you want to permanently delete this post?');"

尝试:

echo "<td><a onclick='return confirm('Are you sure you want to permanently delete this post?');' href='posts.php?id=".$res['id']."'>view</a>";

改用:

echo "<td><a onclick="return confirm('Are you sure you want to permanently delete this post?');" href="posts.php?id=".$res['id']."'>view</a></td>";

confirm返回truefalse

添加返回 false 或 true 以避免进一步执行

    if(Confirm())
           return true;
        else
          return false;