为什么单击确定Web表单重置

时间:2011-06-22 14:34:16

标签: javascript asp.net href

我已经编写了以下脚本来使用href弹出一条消息,但是在点击弹出窗口的OK时,表单会重置为什么会发生这种情况

我写的内容如下

<a href="" style="text-decoration: none;" onclick="return confirm('A student need for Accommodated, Modified, or Alternate assessment is determined by the student ARD committee working in collabration with the LPAC and must be documneted in the student IEP ');">
                                ?</a>

在确定之前单击

enter image description here

点击确定后

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:5)

您使用confirm()进行信息弹出是很奇怪的。确定和取消之间没有区别,因此您只需使用alert(),您还需要返回false,因此它实际上不会跟随链接:

<a href="" onclick="confirm('Whatever'); return false;">?</a>

您发布的原始版本是链接到当前页面(并使用现在为空的表单重新加载页面。)

你也可以使用span:

<span onclick="confirm('Whatever');">?</span>

答案 1 :(得分:1)

那是因为在确认框中单击“确定”将返回true,这将导致锚点 '继续'使用它的默认行为,在这种情况下(没有定义的href)将重新加载当前页面。考虑使用不同的标签,例如&lt; span&gt;

编辑:或如下所述,尝试添加

return false;

在标签内的函数调用之后。