JavaScript表单打开";“无限”;标签
我有一个脚本,它得到一个表单,表单中的字段由它自己填充,我还得到了一个代码,可以每隔x秒自动提交表单 问题是我在表单中添加了这个属性(target=“_blank”),但是表单继续执行代码并无限地创建一个新选项卡 我希望我的脚本创建一个用于处理表单的新选项卡,并且在脚本第二次执行时,使用相同的选项卡刷新处理页面 我可以用JavaScript实现吗JavaScript表单打开";“无限”;标签,javascript,jquery,html,forms,tabs,Javascript,Jquery,Html,Forms,Tabs,我有一个脚本,它得到一个表单,表单中的字段由它自己填充,我还得到了一个代码,可以每隔x秒自动提交表单 问题是我在表单中添加了这个属性(target=“_blank”),但是表单继续执行代码并无限地创建一个新选项卡 我希望我的脚本创建一个用于处理表单的新选项卡,并且在脚本第二次执行时,使用相同的选项卡刷新处理页面 我可以用JavaScript实现吗 <form target="_blank" name="myForm" id="myForm" action="process.asp" met
<form target="_blank" name="myForm" id="myForm" action="process.asp" method="post">
field 1:<input type="text" name="field1" id="field1" /><br>
field 2:<input type="text" name="field2" id="field2" /><br>
</form>
<script type="text/javascript"> // code which executes the submit of form operation
window.onload=function(){
var auto = setTimeout(function(){ autoRefresh(); }, 100);
function submitform(){
document.forms["myForm"].submit();
}
function autoRefresh(){
clearTimeout(auto);
auto = setTimeout(function(){ submitform(); autoRefresh(); }, 10000);
}
}
</script>`
字段1:
字段2:
//执行表单提交操作的代码
window.onload=function(){
var auto=setTimeout(函数(){autoRefresh();},100);
函数submitform(){
document.forms[“myForm”].submit();
}
函数autoRefresh(){
clearTimeout(自动);
auto=setTimeout(函数(){submitform();autoRefresh();},10000);
}
}
`
请尝试使用此代码(使用Ajax)。它将帮助您使用ajax,而不会打开任何新选项卡,并帮助您提交带有上次更新日期和时间的表单
它在我的基地工作
请用你的代码试试
<html>
<head>
</head>
<body>
<form target="_self" name="myForm" id="myForm" action="process.asp" method="post">
field 1:<input type="text" name="field1" id="F1" />
<br>
field 2:<input type="text" name="field2" id="F2" />
<br>
<p id="LastDt"></p>
</form>
<script type="text/javascript"> // code which executes the submit of form operation
window.onload = function () {
var auto = setTimeout(function () {
autoRefresh();
}, 100);
function submitform() {
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("LastDt").innerHTML = "Last Update : " + new Date();
}
};
// It send data on process.asp (silently).
xmlhttp.open("POST", "process.asp?field1=" + document.getElementById("F1").value + "&field2=" + document.getElementById("F2").value , true);
xmlhttp.send();
}
function autoRefresh() {
clearTimeout(auto);
auto = setTimeout(function () {
submitform();
}, 10000);
}
}
</script>
</body>
</html>
字段1:
字段2:
//执行表单提交操作的代码
window.onload=函数(){
var auto=setTimeout(函数(){
自动刷新();
}, 100);
函数submitform(){
if(window.XMLHttpRequest)
{
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}否则{
//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“LastDt”).innerHTML=“上次更新:”+新日期();
}
};
//它通过process.asp(静默)发送数据。
xmlhttp.open(“POST”、“process.asp?field1=“+document.getElementById(“F1”).value+”&field2=“+document.getElementById(“F2”).value,true);
xmlhttp.send();
}
函数autoRefresh(){
clearTimeout(自动);
自动=设置超时(函数(){
submitform();
}, 10000);
}
}
您可以在process.asp中添加相同的表单,在第一次提交后打开新选项卡…用于将数据传递到其他选项卡并从那里提交
或者您可以将数据存储在localStorage中,并在process.asp
中使用以侦听更新并发布数据