警告框不能在jsp中工作

时间:2012-03-03 08:13:23

标签: javascript jquery html alert

我在页面上添加了一个时尚的警报框,资源为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> 

2 个答案:

答案 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;
   }
}