添加确认框
这是我的代码,我想在其中添加一个确认框。
我有一个带有两个submit
按钮的表单。我需要带有它们的确认框,然后发送到下一页。我怎样才能做到这一点?
这是确认框的代码,如何将其放在我的表单中?
onclick="return confirm('Are you sure?');"
myform.jsp
<form id="form1" name="form1" method="post" action="">
<p> </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>
答案 0 :(得分: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();
}
});
答案 1 :(得分:0)
试试这个
<form id="form1" name="form1" method="post" action="/your/url.xyz" onsubmit="return confirm('bla bla');">
答案 2 :(得分: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');}
}
答案 3 :(得分: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> </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>
答案 4 :(得分: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>