我在页面上添加了一个时尚的警报框,资源为here。但问题是点击ok
后,confirmsubmit.jsp
未打开。同样在警报cancel
按钮中没有出现原因?
的javascript
<form action="confirmsubmit.jsp" method="POST">
<script type="text/javascript">
<!--
function confirmation() {
var answer = csscody.alert("Confirm submit?")// added csscody here for alert but after clicking ok nothing happens
if (answer){
window.location = "confirmsubmit.jsp";
}
else{
return false;// here cancel button is not coming
}
}
//-->
</script>
</form>
HTML
<input type="text" name="textboxname"/>
<input type="submit" onclick="return confirmation()"/>
</form>
答案 0 :(得分:1)
<强>更新强>
查看下面的代码,它使用按钮而不是链接
<form action="confirmsubmit.jsp" method="POST">
<script type="text/javascript">
$().ready(function() {
$('#btn_submit').click(function(e) {
e.preventDefault();
var that = this;
var text = "si o no compa?";
csscody.confirm(text, {
onComplete: function(e) {
if (e) {
window.location = "confirmsubmit.jsp";
}
else {
return false;
}
}
})
});
});
</script>
<input type="text" name="textboxname"/>
<input type="submit" id="btn_submit" onclick="return confirmation()"/>
</form>
答案 1 :(得分:0)
您将不得不使用confirm
代替alert
,这将提供返回true
的确定和取消按钮和false
分别。并从return
onclick
HTML
<form action = "confirmsubmit.jsp" method = "POST">
<input type = "text" name = "textboxname" />
<input type = "submit" onclick = "confirmation();" />
</form>
的Javascript
function confirmation() {
var answer = confirm("Confirm submit?");
if (answer){
window.location = "confirmsubmit.jsp";
}
else{
return false;
}
}