取消按钮不适用于确认窗口
Cancel button not working for the confirm window
我正在尝试验证JavaScript中的单选按钮,这是我的代码:
if (document.ExamEntry.GCSE.checked == true) {
confirm("You have selected GCSE. Is this correct?");
}
if (document.ExamEntry.AS.checked == true) {
confirm("You have selected AS. Is this correct?");
}
if (document.ExamEntry.A2.checked == true) {
confirm("You have selected A2. Is this correct?");
}
确认窗口显示,单击"提交"成功将带您进入下一页,但取消按钮似乎不起作用——它只是在我希望它停留在页面上时带您进入该页面,以便您可以更改选项。
我试过一些东西,比如返回结果;结果=错误
它们要么不起作用,要么起作用,反之亦然,因此取消按钮通过保持在同一页面上起作用,但提交按钮也会发生这种情况。
查看confirm上的文档。上面写着,
结果是一个布尔值,指示是否选择了OK或Cancel(true表示OK)
这意味着您的每一行都应该检查返回值。一种简洁的方法是,例如:
if (!confirm("You have selected A2. Is this correct?")) {
// event.cancel = true, or whatever you need to do on your side to cancel
} // otherwise fall through and do what you're doing.
现在的情况是,由于您从未考虑过confirm
的返回值,因此您总是陷入"成功"的情况。
var gcse = true,
as = true,
a2 = true;
if (document.ExamEntry.GCSE.checked == true) {
gcse = confirm("You have selected GCSE. Is this correct?"));
}
if (document.ExamEntry.AS.checked == true) {
as = confirm("You have selected AS. Is this correct?");
}
if (document.ExamEntry.A2.checked == true) {
a2 = confirm("You have selected A2. Is this correct?");
}
if (gcse && as && a2) {
// you're golden
window.location.href = 'otherpage'
}
if (document.ExamEntry.GCSE.checked == true) {
if(confirm("You have selected GCSE. Is this correct?")) {
// do something
}
} if (document.ExamEntry.AS.checked == true) {
if(confirm("You have selected AS. Is this correct?")) {
// do something
}
}
if (document.ExamEntry.A2.checked == true) {
if(confirm("You have selected A2. Is this correct?")) {
//do something
}
}
相关文章:
- 当我编码窗口时如何返回真或假.确认自己
- 窗口确认在 AJAX 帖子中打印 HTML 标签
- 取消按钮不适用于确认窗口
- 在chrome上显示类似于关闭窗口时的firefox的警报消息.确认消息”;离开"或“;留在这个页面上&quo
- 为什么这个JS确认窗口没有在表单提交时启动
- 在幻像.js中确认警报窗口
- 如何在表单中单击重置按钮时确认弹出窗口
- 在 JavaScript 确认窗口中将 Unicode 转换为字符
- 如何在提交按钮上设置javascript弹出确认窗口的样式
- 脚本抛出不需要的确认窗口.如何删除
- Javascript确认窗口无回发
- OnClick Javascript确认窗口
- JavaScript确认窗口
- CakePHP确认窗口没有出现
- 确认窗口关闭
- Jquery确认窗口不工作,取消按钮点击
- 弹出确认窗口
- 关闭对话框时出现确认窗口的问题
- 我如何编辑Javascript / Bootbox/ Bootstrap确认窗口
- c#2.0-javascript确认窗口,获取bool值