当点击approve button时会调用js验证,成功后跳转到Success页面现在的问题是当点击button,验证不通过,跳出alert提示后,程序仍然在继续执行并跳转到Success页面
如何在js验证不成功时阻止跳转始终留在该页面。
请指点,谢。

解决方案 »

  1.   

    代码帖出来看看一般来说 验证的话 ,需要 return false
      

  2.   


    function initForm() {
    sales_Validation();
    }
    function sales_Validation(){
    $("a:contains('Apply')").bind("click",sales_budget_Validation);
    };
    function sales_budget_Validation(){
    if ($("#P66_IS_SALES").val() == 'Y' && $("#P66_FORM_ID").val() != '' && $("#P66_TOTAL_BASE_AMT").val() != 0 ){
    alert("已经超过总额");
                          return false;
    }

    }
    };return false 还是会继续跳转
      

  3.   

    <html><head>
    <script type="text/javascript" src="jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("p").click(function(){
      $(this).hide();
    });$("input:submit").click(function() {
        alert('1');
        return false;
    });
    });
    </script>
    </head><body>
    <form method="post" action='b.html'>
     
    <input type="submit" value='submit' style="height: 26px"/>
    </form>
    </body></html> 
      

  4.   

    3楼,return false 没用,跳出提示框后页面仍然在跳转
      

  5.   

    html上你是如何使用这个函数的?
      

  6.   


    <script type="text/javascript">
      $(function() {
    initForm();
      });
    </script>
      

  7.   

    看你好像是一个A链接,但是也可以啊。
    <html><head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){$("input:submit").click(function() {
        alert('1');
        return false;
    });
    $("a").bind('click',clk);
    });function clk(){
      alert(2);
       return false;
    }
    </script>
    </head><body>
    <form method="post" action='b.html'>
     
    <input type="submit" value='submit' style="height: 26px"/>
    <a href='b.html'  >2</a>
    </form>
    </body></html> 
      

  8.   


        $("a:contains('Apply')").bind("click",sales_budget_Validation);    改成 
        $("a:contains('Apply')").bind("click",function(){return sales_budget_Validation});    
      

  9.   

    哎呀呀,这样不知道行不行,平常我都是在元素或表单里面写 onclick="return fun()" 的
      

  10.   

    如果是表单 如果按钮是submit的 <form onsubmit=return 校验函数();> 这时候就是1楼说的return false 就OK了 ;如果是button 校验函数写在其onclick事件中 那这时候不跳转就要写成return;如果不是表单 一般情况写成return;也就可以了
      

  11.   

    如果用<form action>的话,只能使用return了。。
      

  12.   

    #11楼正解
    <input type="submit" onclick="return display()" value="确认" />
    display()即为判定返回值的函数,return的值为true,则跳转;否则滞留当前页面。