无法获得确认框出现在提交上

时间:2013-02-18 16:48:27

标签: php javascript confirm onsubmit

我尝试使用onsubmit="return confirm('Do you really want to submit the form?')"在用户通过单击“提交”按钮删除项目之前显示警告。我无法显示确认框,只是继续直接删除该项目。

任何人都可以在我的代码中看到我可能出错的地方吗?我已经尝试更改双引号和单引号,但没有任何努力已经出现确认框。

我的代码如下。

    echo '<td> <form method="post" action="deleteassign.php" name="deleteassignform"
 id="deleteassignform" onsubmit="return confirm('Do you really want to submit the form?')">';
    echo '<input type="hidden" name="quizidvalue" id="quizidvalue" value="'.$sendquizid.'" />';
    echo '<input type="hidden" name="classidvalue" id="classidvalue" value="'.$sendclassid.'" />';
    echo '<input type="submit" name="deleteassignment" id="deleteassignment" value="Delete This Assignment"> </form> </td> </tr>';

5 个答案:

答案 0 :(得分:2)

改变你的:

return confirm('Do you really want to submit the form?')

return confirm(\'Do you really want to submit the form?\')

这应该可以解决这个给你的问题,因为它肯定是错误的。

答案 1 :(得分:1)

为了输出......

onsubmit="return confirm('Do you really want to submit the form?')"

...你需要在PHP端正确地转义引号。请尝试以下操作(请注意单引号前的反斜杠):

echo '<td> <form method="post" action="deleteassign.php" name="deleteassignform"
 id="deleteassignform" onsubmit="return confirm(\'Do you really want to submit the form?\')">';

答案 2 :(得分:0)

为什么不直接将代码放在按钮中?

<input type="submit" name="deleteassignment" id="deleteassignment" 
value="Delete This Assignment" onclick="return confirm('Do you really want to delete?')">

答案 3 :(得分:0)

你的报价错了。您可以更好地使用此表单,因此所有引号都是正确的:

?><td> <form method="post" action="deleteassign.php" name="deleteassignform"
id="deleteassignform" onsubmit="return confirm('Do you really want to submit the form?')">
<input type="hidden" name="quizidvalue" id="quizidvalue" value="<?= htmlspecialchars($sendquizid) ?>" />
<input type="hidden" name="classidvalue" id="classidvalue" value="<?= htmlspecialchars($sendclassid) ?>" />
<input type="submit" name="deleteassignment" id="deleteassignment" value="Delete This Assignment"> </form> </td> </tr>
<?php

答案 4 :(得分:0)

您的代码输出的代码应如下所示:

<form method="post" action="deleteassign.php" name="deleteassignform"
 id="deleteassignform" onSubmit="return confirm('Do you really want to submit the form?');">

请注意confirm函数内的引用。