0

我正在尝试使用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>';
4

5 回答 5

2

改变你的:

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

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

这应该可以解决这给您带来的任何引用问题,因为它肯定被错误地引用了。

于 2013-02-18T17:03:46.697 回答
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?\')">';
于 2013-02-18T17:04:37.560 回答
0

为什么不直接把代码放在按钮里呢?

<input type="submit" name="deleteassignment" id="deleteassignment" 
value="Delete This Assignment" onclick="return confirm('Do you really want to delete?')">
于 2013-02-18T16:50:24.067 回答
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
于 2013-02-18T17:00:34.123 回答
0

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

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

注意函数内部的引用confirm

于 2013-02-18T17:10:36.053 回答