alert提示后如何阻止页面的跳转 当点击approve button时会调用js验证,成功后跳转到Success页面现在的问题是当点击button,验证不通过,跳出alert提示后,程序仍然在继续执行并跳转到Success页面如何在js验证不成功时阻止跳转始终留在该页面。请指点,谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码帖出来看看一般来说 验证的话 ,需要 return false 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 还是会继续跳转 <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> 3楼,return false 没用,跳出提示框后页面仍然在跳转 html上你是如何使用这个函数的? <script type="text/javascript"> $(function() { initForm(); });</script> 看你好像是一个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> $("a:contains('Apply')").bind("click",sales_budget_Validation); 改成 $("a:contains('Apply')").bind("click",function(){return sales_budget_Validation}); 哎呀呀,这样不知道行不行,平常我都是在元素或表单里面写 onclick="return fun()" 的 如果是表单 如果按钮是submit的 <form onsubmit=return 校验函数();> 这时候就是1楼说的return false 就OK了 ;如果是button 校验函数写在其onclick事件中 那这时候不跳转就要写成return;如果不是表单 一般情况写成return;也就可以了 如果用<form action>的话,只能使用return了。。 #11楼正解<input type="submit" onclick="return display()" value="确认" />display()即为判定返回值的函数,return的值为true,则跳转;否则滞留当前页面。 用javascript给action动态赋值,ie可以,但fox不行,为什么? Hash 遍历怎么取不到值(62分求解) 提交表单问题! 急,求助,装载页面显示动画 如何使鼠标移到图片上出来链接的选项 如果鼠标点上去后改变字颜色? 请问如何取得一个下拉框的值(在线等) 问一个关于request的问题 寻找上海地区美工兼职 求助slidesjs这个插件的问题 怎么能循环、顺序地从iframe中提取信息? 验证身份证,没有验让完就提交了
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 还是会继续跳转
<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>
<script type="text/javascript">
$(function() {
initForm();
});
</script>
<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>
$("a:contains('Apply')").bind("click",sales_budget_Validation); 改成
$("a:contains('Apply')").bind("click",function(){return sales_budget_Validation});
<input type="submit" onclick="return display()" value="确认" />
display()即为判定返回值的函数,return的值为true,则跳转;否则滞留当前页面。