jquery表单提交函数不工作在php,我想提交超时后的形式,但它不工作我的代码如下。谁能给出它的解
<script>
$( document ).ready(function() {
var c=10;
var t;
timedCount();
function timedCount()
{
var hours = parseInt( c / 3600 ) % 24;
var minutes = parseInt( c / 60 ) % 60;
var seconds = c % 60;
var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
$('#timer').html(result);
if(c == 0 )
{
// form.submit();
//$('#scoretarget').submit();
//setConfirmUnload(false);
document.formsubmit.submit();
//alert("Your form will be submited");
//$( "#scoretarget" ).submit();
// $('#scoretarget').submit();
//$( "#target" ).submit();
//window.location="logout.html";
}else{
c = c - 1;
t = setTimeout(function(){
timedCount()
},1000);
}
}
});
</script>
检查这个
$( document ).ready(function() {
var c=10;
var t;
timedCount();
function timedCount()
{
var hours = parseInt( c / 3600 ) % 24;
var minutes = parseInt( c / 60 ) % 60;
var seconds = c % 60;
var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
$('#timer').html(result);
if(c == 0 )
{
// form.submit();
//$('#scoretarget').submit();
//setConfirmUnload(false);
//document.formsubmit.submit();
alert("Your form will be submited");
$("#scoretarget" ).submit();
// $('#scoretarget').submit();
//$( "#target" ).submit();
//window.location="logout.html";
}
else{
c = c - 1;
t = setTimeout(function(){
timedCount()
},
1000);
}
}
});
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<form id="scoretarget" name="formsubmit" action="congrasulations.php" method="POST">
</form>
<div id="timer"></div>
尝试使用jquery和$( "#scoretarget" ).submit();
提交表单。
这里是整个HTML代码,而不是代码片段。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$( document ).ready(function() {
var c=10;
var t;
timedCount();
function timedCount()
{
var hours = parseInt( c / 3600 ) % 24;
var minutes = parseInt( c / 60 ) % 60;
var seconds = c % 60;
var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
$('#timer').html(result);
if(c == 0 )
{
// form.submit();
//$('#scoretarget').submit();
//setConfirmUnload(false);
//document.formsubmit.submit();
alert("Your form will be submited");
$("#scoretarget" ).submit();
// $('#scoretarget').submit();
//$( "#target" ).submit();
//window.location="logout.html";
}
else{
c = c - 1;
t = setTimeout(function(){
timedCount()
},
1000);
}
}
});
</script>
<form id="scoretarget" name="formsubmit" action="congrasulations.php" method="POST">
</form>
<div id="timer"></div>
</body>
</html>
使用下面的代码提交表单而不是document.formsubmit.submit();
$('#formId')[0].submit();
并检查表单中是否有命名为"submit"的元素,如果有,将元素名称更改为其他名称,因为它可能会阻止表单提交
1。这段代码
else{
c = c - 1;
t = setTimeout(function(){
timedCount()
},
1000);
}
应:else{
t = setTimeout(function(){
timedCount();
c = c - 1;
},
1000);
}
以前,您的代码只减少c
一次。您应该在 setTimeout
回调函数中递减c
,因此它将被超时值递减,这是1000ms。
2。在jQuery中触发表单提交,使用:$('form').trigger('submit');
来源:http://api.jquery.com/trigger/