【发布时间】:2014-04-17 15:31:32
【问题描述】:
我有一个 html 表单,当我按下提交按钮时会发送该表单-(input type=submit).. 同样在同一个按钮上,我有一个 onclick 事件,它在按下按钮时触发,但是由于按钮 = 提交的类型,我触发的脚本中的 window.location 不起作用,当我将按钮输入类型更改为时它工作正常按钮,但 html 表单提交不起作用.. 有什么方法可以同时工作..请不要通过ajax post告诉发布表格..
这是我的 html 按钮
<input type="submit" class="submit-login" name="forgotpass" id="" onclick="forgotfunction()"/>
这是我的脚本
<script type="text/javascript">
function forgotfunction(){
var len = $('#forgetpass').val();
if (len.length == 10){
var num = "<?php echo $_SESSION['msg'];unset($_SESSION['msg']);?>"; //getting error from parameter.
alert(num);
if(num=="success")
$('#modalLink').trigger("click");
if(num=="cannotsend")
alert("Error! Cannot send mail.,Please try Again!");
if(num=="invalid")
alert("Mobile number is not Registered");
alert(num);
alert(window.location.href.split("?")[0]);
window.location = window.location.href.split("?")[0];//reloading page
//$('#aforgot').trigger('click');
}
}
</script>
【问题讨论】:
-
您的代码刷新页面,不能同时刷新页面和提交表单,即使使用按钮输入,手动提交表单。
-
提交表单后刷新..为什么会出错??
标签: javascript jquery html ajax forms