用JS咯
你这个需求显然不是5S让页刷新一次,而是提交一次吧?
var time;
var second
function refreshOnTime()
{
if(time==null)
time=document.getElementById("txtRefreshTime").value;
if(second==null)
second=parseInt(time);
second=second-1;
if(second==0)
{
//document.getElementById("txtRefreshTime").value=time;
second=time;
document.getElementById("btnRefresh").click();
}
}
window.setInterval(refreshOnTime,1000)
可以让time等于5,在页面放一个隐藏的button,点击button即保存你的数据。5秒让这个button点一次:
document.getElementById("btnRefresh").click();
你这个需求显然不是5S让页刷新一次,而是提交一次吧?
var time;
var second
function refreshOnTime()
{
if(time==null)
time=document.getElementById("txtRefreshTime").value;
if(second==null)
second=parseInt(time);
second=second-1;
if(second==0)
{
//document.getElementById("txtRefreshTime").value=time;
second=time;
document.getElementById("btnRefresh").click();
}
}
window.setInterval(refreshOnTime,1000)
可以让time等于5,在页面放一个隐藏的button,点击button即保存你的数据。5秒让这个button点一次:
document.getElementById("btnRefresh").click();
非常感谢您!~
这个隐藏的button要怎么写呢?
刚开始弄,不太会,请给个例子吧,谢谢
就隐藏了。
具体点button执行的服务端代码你自己写就OK了。
document.main.action = "save.jsp";
document.main.submit();
好像是:setInterval
function f_pageload()
{
window.location.reload();
}
window.setInterval(f_pageload,1000);
写的比较简单,嘿嘿!
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"></asp:Timer>
在Timer1_Tick时间里面让它刷新
test.asp<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head><body>
<form action="test.asp" name="main">
<textarea name="test"><%=Request("test")%></textarea>
</form>
<div><%=Request("test")%></div>
</html>
<script>
function Input(){
document.main.submit();
}
window.setInterval(Input,1000);
</script>该例相对简单易懂,但用户体验极差,提交时用户被强迫中断操作!我写了一个后台无刷新提交的例子,请看下一回复!
test.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
If Request("act")="ajax" Then
Response.Expires=-1
Response.Write(Request("info"))
Response.End()
End If
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var xmlHttp
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function Input()
{
var objHTML = document.getElementById("showit").innerHTML;
objHTML = "正在获取数据,请稍候……";
xmlHttp =GetXmlHttpObject();
//var xmlHttp = main.xmlHttp;
if (xmlHttp==null){objHTML="您的浏览器不支持本站程序,请改用其他浏览器!";return;}
var url="test.asp";
url+="?act=ajax&info="+document.getElementById("text").value;
xmlHttp.onreadystatechange=ChangeCont;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function ChangeCont()
{
if(xmlHttp.readyState==4)
{
document.getElementById("showit").innerHTML=xmlHttp.responseText;
}
}
window.setInterval("Input()",1000);
</script>
</head><body>
<form id="main" action="test.asp" method="get">
<textarea id="text"></textarea>
</form>
<div id="showit"></div>
</html>采用ajax方式,用户无感!