放入<! - ?php? - >时不会出现确认(“消息”)

时间:2016-12-05 23:41:26

标签: php anchor href confirmation

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>";
    }
?>

但是没有出现确认框。

3 个答案:

答案 0 :(得分:1)

您在单引号内使用单引号。使用双引号代替包装代码:

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

答案 1 :(得分:0)

只需更改此代码即可。

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

答案 2 :(得分:0)

您滥用了单引号和双引号。你必须在引号上加上斜杠()来逃避。 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>";