放入 <?php ?> 时不会出现 Confirm("Message")
Confirm("Message") does not appear when putting in <?php ?>
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>";
}
?>
但是没有出现确认框。
您在单引号内使用了单引号。使用双引号来包裹您的代码:
<a href='#' onclick="return confirm('Confirmation Message')">Link</a>
只需更改此代码,它就会起作用。
echo "<a href='deleteCom.php?id=$commentID' onclick="return confirm('Delete this comment?')">Delete</a>";
你误用了单引号和双引号。您必须在引号上加上斜杠 () 才能转义。 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>";
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>";
}
?>
但是没有出现确认框。
您在单引号内使用了单引号。使用双引号来包裹您的代码:
<a href='#' onclick="return confirm('Confirmation Message')">Link</a>
只需更改此代码,它就会起作用。
echo "<a href='deleteCom.php?id=$commentID' onclick="return confirm('Delete this comment?')">Delete</a>";
你误用了单引号和双引号。您必须在引号上加上斜杠 () 才能转义。 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>";