简体   繁体   English

单击提交按钮后停留在同一页面上

[英]Staying on same page after clicking submit button

I have a function "myfunction" applied on a submit button.我在提交按钮上应用了 function “myfunction”。 The function shows a dialog box when the page is submitted and asks user if he is sure to submit the page? function在提交页面时会显示一个对话框,询问用户是否确定提交页面?

The code of HTML button is: HTML按钮代码为:

<h:commandButton id="submit" value="Brewery 1" onclick="myfunction()" styleClass="button1">
<f:actionListener binding="#{loginweb.setNewUsernameAndCreateUser('Brewery1')}"/>
</h:commandButton>

**function myfunction(e)**
        {
         if(!confirm('Are you sure to proceed with this role?')) {
                e.preventDefault();
         }
        else {
         return false;
            }
        }

But when I press cancel (on appeared dialog box) the page is still submitted.但是当我按下取消(在出现的对话框上)时,页面仍然被提交。 What I am doing wrong?我做错了什么? Thanks谢谢

It doesn't look like you're passing the click event to myfunction .看起来您没有将 click 事件传递给myfunction Try onclick="myfunction(event)" .试试onclick="myfunction(event)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM