【问题标题】:Confirm("Message") does not appear when putting in <?php ?>输入 <?php ?> 时没有出现 Confirm("Message")
【发布时间】:2016-12-05 23:41:25
【问题描述】:

onclick='return confirm('Delete this comment?')' 似乎根本不起作用:

<?php           
     if($sesType == 'Admin') {
        echo "<a href = 'editCom.php?id=$commentID'>Edit</a> ";
        echo "<a href='deleteCom.php?id=$commentID' onclick='return confirm('Delete this comment?')'>Delete</a>";
    } else if($_SESSION["username"] != NULL AND $_SESSION["username"] == $postname) {
        echo "<a href = 'editCom.php?id=$commentID'>Edit</a>  ";
        echo "<a href='deleteCom.php?id=$commentID' onclick='return confirm('Delete this comment?')'>Delete</a>";
    }
?>

但是没有出现确认框。

【问题讨论】:

  • 我也试过用javascript做,但结果一样
  • 您正在以一种行不通的方式混合引用字符。
  • 查看浏览器的 javascript 控制台,单击锚点时可能会看到错误消息。

标签: php anchor href confirmation


【解决方案1】:

您在单引号内使用单引号。改为使用双引号来包装您的代码:

&lt;a href='#' onclick="return confirm('Confirmation Message')"&gt;Link&lt;/a&gt;

【讨论】:

    【解决方案2】:

    只需更改此代码即可。

    echo "<a href='deleteCom.php?id=$commentID' onclick="return confirm('Delete this comment?')">Delete</a>";
    

    【讨论】:

      【解决方案3】:

      您误用了单引号和双引号。您必须在引号上加上斜杠 () 才能转义。 html 应如下所示:

       <a href='#' onclick="return confirm('Confirmation Message')">Link</a>   
      

      注意单引号应该插入双引号""

      来自您的代码:

      echo " <a href='deleteCom.php?id=$commentID' onclick='return confirm('Delete this comment?')'>Delete</a>";
      

      应该是:

       echo "<a href=\"deleteCom.php?id={$commentID}\" onclick=\"return confirm('Delete this comment?')\">Delete</a>";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-01
        相关资源
        最近更新 更多