Javascript - 在警报消息后停止继续 [英] Javascript - stop proceeding after alert message

查看:83
本文介绍了Javascript - 在警报消息后停止继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网页应用程序中,在登录页面中,我有一个复选框。输入用户名/密码后,如果用户没有勾选复选框(T& C),则不应将其带到主页,并显示警告错误消息。

In my web application, in the login page, I have a checkbox. After entering the username/password, if the user doesn't tick the checkbox (T&C), he should not be taken to the home page, and an alert error message will be shown.

我试过以下代码。但它没有用。也就是说,显示警告消息。但是用户被带到下一页(主页)。我尝试返回false,但没有运气。

I have tried the following code. But it is not working. That is, an alert message is shown. But the user is taken to the next page(home page). I tried returning false, but no luck.

有人能说出如何解决这个问题吗?

Can anyone tell how to fix this?

function doSubmit() {
    var checkbox = document.getElementById("terms");
    if (!checkbox.checked) {
        alert("error message here!");
        return;
    }
    document.getElementById("f").submit();
}​  

我从

<input id="proceed" onclick="doSubmit()" type="submit" value="${fn:escapeXml(submit_label)}" />


推荐答案

尝试将输入类型更改为按钮而不是提交,将提交操作委托给JS函数:

Try changing the input type to button instead of submit, delegating the submit action to JS function:

<input id="proceed" onclick="doSubmit()" type="button" value="${fn:escapeXml(submit_label)}" />

这篇关于Javascript - 在警报消息后停止继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆