【发布时间】:2014-05-01 03:33:04
【问题描述】:
所以我试图让用户在提交表单之前确认他们的操作,所以我尝试使用确认框。当我测试它时,即使我在确认框中按了取消,表单也提交了。所以我尝试将变量'c'设置为false,然后说如果c==true,提交表单,表单仍然提交!我不明白为什么会这样。任何帮助将不胜感激!
所以为了清楚起见,表单仍然在以下代码中提交:
<button onclick=\"extendBids('$studentID')\">Extend Bid</button>
<input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>
function extendBids(studentID) {
document.getElementById(studentID+" 2").checked=true;
//var c=confirm("Are you sure? This action cannot be undone.");
var c=false;
if (c==true){
document.forms["addToRush"].submit();
}
}
【问题讨论】:
-
给定的代码 sn-p 有效。有没有可能在更远的地方——这里看不到——触发提交?还是在
input type='button'的处理程序中调用此代码,这可能导致表单提交。 -
好的,我提供了更多关于从哪里调用它的信息
-
@garethb 称之为。看到上下文,这是一个已知问题。查看他链接到的帖子。
标签: javascript forms