点击确认始终删除

时间:2013-07-29 16:00:47

标签: javascript php

在php文件中,我有以下代码:

echo '<form action="../apps" method="post" enctype="multipart/form-data"">';
    echo '<input type="hidden" name="check" />';
    echo '<input type="hidden" name="ID" value="'.$ID.'" />';
    echo '<input type="submit" value="Delete" onclick="confirmDelete()" "style="margin-right: 5px;" />';
echo '</form>';

功能:

function confirmDelete()
{
    var agree= confirm("are you sure?");
    if (agree == true)
        {
        return ('<?php  
            if (isset($_POST['check']))
            {
                if ($queryType == "apps")
                {
                    $deletePath = "delete/";
                    include $deletePath.'deleteApp.php';
                }
            }
            ?>');
        return true;
        }
    else
        {
        alert("you pressed cancel");
        return false;}
}

按下取消时会显示警告框,但无论如何都会删除该操作,而不是取消操作。我是javascript的新手,我不确定是什么问题。

按OK按钮可正确删除所有内容,但calcel按钮也会立即删除该应用。

1 个答案:

答案 0 :(得分:2)

您需要在onclick属性中返回结果。

echo '<input type="submit" value="Delete" onclick="return confirmDelete()" "style="margin-right: 5px;" />';

ps:您不必回显大量的HTML字符串。您可以使用此

轻松替换所有echo次调用
<form action="../apps" method="post" enctype="multipart/form-data"">
  <input type="hidden" name="check" />
  <input type="hidden" name="ID" value="<?php echo $ID ?>" />
  <input type="submit" value="Delete" onclick="return confirmDelete()" />
</form>