Javascript 如何在提交按钮之前添加确认框?

Javascript 如何在提交按钮之前添加确认框?,javascript,html,Javascript,Html,添加确认框 这是我的代码,我想添加一个确认框 我有一个带有两个submit按钮的表单。我需要他们的确认框,然后发送到下一页。我该怎么做? 这是确认框的代码,我如何将其放入表格中 onclick="return confirm('Are you sure?');" myform.jsp <form id="form1" name="form1" method="post" action=""> <p>&nbsp;</p> <p a

添加确认框

这是我的代码,我想添加一个确认框

我有一个带有两个
submit
按钮的表单。我需要他们的确认框,然后发送到下一页。我该怎么做? 这是确认框的代码,我如何将其放入表格中

onclick="return confirm('Are you sure?');"
myform.jsp

<form id="form1" name="form1" method="post" action="">
    <p>&nbsp;</p>
    <p align="center">Enter your choice:-
    <label> <br />
    <label>
       <input type="submit" name="Submit" value="delete" onclick="this.form.action='logi.jsp?flag=1&act=1';this.form.submit();" />
    </label>
    <br />
    </br>
    <label>
        <input type="submit" name="Submit" value="Delete" onclick="this.form.action='delete1.jsp?flag=1&act=1';this.form.submit();" />
    </label>
    <br/>
    </div>
</form>

输入您的选择:-



试试这个

<form id="form1" name="form1" method="post" action="/your/url.xyz" onsubmit="return confirm('bla bla');">


功能确认(此,foo1)
{
var foo=confirm('你确定吗?');
if(foo){this.form.action=foo1;this.form.submit();}
else{alert('Try Later');}
}

以下代码片段就是解决方案。您需要删除
this.form.submit()
,因为按钮是提交按钮,默认情况下它们是提交按钮

只需将
onsubmit=“return window.confirm('you sure?');“
添加到表单中,然后从提交按钮中删除
this.form.submit()

<form id="form1" name="form1" method="post" action="" onsubmit=" return window.confirm('Are you sure?');">
                        <p>&nbsp;</p>
                        <p align="center">Enter your choice:-
                            <label> <br />


         <label>
           <input type="submit" name="Submit" value="delete" onclick="this.form.action='logi.jsp?flag=1&act=1';" />
            </label>
                                <br />

                            </br>
                   <label>
                 <input type="submit" name="Submit" value="Delete" onclick="this.form.action='delete1.jsp?flag=1&act=1';" />
           </label>
                                <br/>

                        </div></form>

输入您的选择:-



请参见此代码确认框,其中一个建议是您的代码需要大量改进
函数disp_confirm()
{
var r=确认(“按下按钮!”)
如果(r==true)
{
警报(“您按了OK!”)
}
其他的
{
警报(“您按了取消!”)
}
}

在button类中尝试以下操作

$('.class').appendTo('body')
  .html('<div><h6>Yes or No?</h6></div>')
  .dialog({
  modal: true, title: 'message', zIndex: 10000, autoOpen: true,
  width: 'auto', resizable: false,
  buttons: {
      Yes: function () {
          doFunctionForYes();
          $(this).dialog("close");
      },
      No: function () {
          doFunctionForNo();
          $(this).dialog("close");
      }
  },
  close: function (event, ui) {
      $(this).remove();
  }
});
$('.class').appendTo('body'))
.html('是或否?')
.对话({
模态:真,标题:“消息”,zIndex:10000,自动打开:真,
宽度:“自动”,可调整大小:false,
按钮:{
是:函数(){
doFunctionForYes();
$(此).dialog(“关闭”);
},
否:函数(){
doFunctionForNo();
$(此).dialog(“关闭”);
}
},
关闭:功能(事件、用户界面){
$(this.remove();
}
});

第二个按钮操作的位置??下面的代码传递图像和文本字段。在display.jsp中的post请求之后,如果显示enctype=“multipart/form data”和图像,则文本字段值为null。如果未使用enctype,则会给出textfield的正确值,并且不会显示任何图像。我们可以在JSP中从同一个页面同时获取图像和文本吗?
See this code confirm box works in this way and one sugesstion your code need a lot pf improvement

<html>
<head>
<script>
function disp_confirm()
{
var r=confirm("Press a button!")
if (r==true)
  {
  alert("You pressed OK!")
  }
else
  {
  alert("You pressed Cancel!")
  }
}
</script>
</head>
<body>

<input type="button" onclick="disp_confirm()" value="Display a confirm box">

</body>
</html> 
$('.class').appendTo('body')
  .html('<div><h6>Yes or No?</h6></div>')
  .dialog({
  modal: true, title: 'message', zIndex: 10000, autoOpen: true,
  width: 'auto', resizable: false,
  buttons: {
      Yes: function () {
          doFunctionForYes();
          $(this).dialog("close");
      },
      No: function () {
          doFunctionForNo();
          $(this).dialog("close");
      }
  },
  close: function (event, ui) {
      $(this).remove();
  }
});