时间:2021-07-22 07:46:59 | 栏目:JavaScript代码 | 点击:次
ajax局部刷新
<script> setInterval("refreshTime()",1000); //每格1秒刷新一次 funciton refreshTime() { var dateObj = new Date(); time.innerHTML = dateObj.toLocaleDateString(); //刷新div里面的内容 } </script> <div id=time> </div>
function doRef() { var url = "xxx.aspx" var dateRequest = new ActiveXObject("Microsoft.XMLHTTP"); dateRequest.abort() ; dateRequest.open( "GET", url , true ); dateRequest.onreadystatechange = onSendSelf ; dateRequest.send() ; function onSendSelf() { if( dateRequest.readyState != 4 ) { return ; } var theDate = dateRequest.responseText ;//如果出现编码问题,可以在服务端escape一下,然后在这里使用unescape( responseText ) theDiv.innerHTML = theDate ; } } setInterval( doRef , 1000 ) ;//1秒刷新一次,有点快
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"> </asp:Timer> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </ContentTemplate> </asp:UpdatePanel> </form>
=====在后台Timer1_Tick事件加上
// Interval="1000" 是设置刷新的时间间隔
TextBox1.Text=DateTime.Now
看下就明白了