使用javascript如何实现页面加载时自动提交表单

返回网页设计技术
2回复贴,共1页,点击数:1043

给form标签一个id,比如:id="myForm"
原生javascript代码:

window.onload= function(){
document.getElementById('myForm').submit();
}

jQuery代码:

$(function(){
$('#myForm').submit();
});
1楼 2021/03/06 09:29

<%

if Request.QueryString("action")="loadsubmit" then

Response.Write("自动提交")

end if

%>

<body>
<form id="form1" name="form1" method="post" action="?action=loadsubmit">
<input name="text1" type="text" value="自动提交" />
</form>
<script>
var i=3;//3秒后自动提交
function load_submit()
{
if(i==0)
{
document.form1.submit();
clearTimeout(load_t);
}
document.form1.text1.value=i+" 秒后提交";
i--;

var load_t=setTimeout("load_submit()",1000);

}

load_submit();

</script>

</body>

扩展资料

1,不断提交表单:

<form name="hiddenForm" action="xxx">
<input type="hidden" name="code" value=<%=code%>> 
<input type="hidden" name="informId" value=<%=id%>>
</form>
<script>
document.hiddenForm.submit()
</script>

2,表单只提交一次:

<script>

function submitForm() {

var frm = document.getElementById("hiddenform");

rm.submit();

}

</script>

</head>

<body onload="submitForm();">

<form id="hiddenform"

action="${pageContext.request.contextPath}/informController/countRead.action">

<input type="hidden" name="code" value=<%=code%>> 

<input type="hidden" name="informId" value=<%=id%>>

</form>

</body>
2楼 2021/03/06 09:35 收起回复

哇,高级技术贴,精华

3楼 2021/03/06 09:41 收起回复
您未登录,没有发贴权限[点此登录]