2

添加确认框

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

我有一个带有两个submit按钮的表单。我需要他们的确认框,然后发送到下一页。我怎样才能做到这一点?这是确认框的代码,我怎样才能把它放在我的表格中?

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

我的表单.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>
4

5 回答 5

2

在按钮类上试试这个

$('.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();
  }
});
于 2013-01-08T09:38:03.073 回答
0

试试这个

<form id="form1" name="form1" method="post" action="/your/url.xyz" onsubmit="return confirm('bla bla');">
于 2013-01-08T09:26:55.563 回答
0
<input type="submit" name="Submit" value="Delete" onclick='confirm(this,"delete1.jsp?flag=1&act=1")' />
<input type="submit" name="Submit" value="delete" onclick='confirm(this,"logi.jsp?flag=1&act=1")' />

function confirm(this,foo1)
{
var foo = confirm('Are you sure?');
if (foo) {this.form.action=foo1;this.form.submit();}
else {alert('Try Later');}
}
于 2013-01-08T09:30:57.520 回答
0

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

只需添加onsubmit=" return window.confirm('Are 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>
于 2013-01-08T09:33:34.957 回答
0
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> 
于 2013-01-08T09:36:45.623 回答