问题描述
要让定时器的时间改成动态的怎么写,这样为什么不行varms=document.getElementById("Hid_ms").value;setInterval("checkisnew()",ms);
解决方案
解决方案二:
给你一个倒计时的程序。<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default7.aspx.cs"Inherits="Default7"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>UntitledPage</title><scripttype="text/javascript">varTotalMinutes=5;varTotalMilliSeconds=5*60*1000;functiontakeCount(){//计数减一TotalMilliSeconds-=1000;//计算时分秒varhours=Math.floor(TotalMilliSeconds/(1000*60*60))%24;varminutes=Math.floor(TotalMilliSeconds/(1000*60))%60;varseconds=Math.floor(TotalMilliSeconds/1000)%60;//将时分秒插入到html中document.getElementById("RemainH").innerHTML=hours;document.getElementById("RemainM").innerHTML=minutes;document.getElementById("RemainS").innerHTML=seconds;window.setTimeout("takeCount()",1000);}</script></head><body><formid="form1"runat="server"><div><divid="CountMsg">倒计时还有:<strongid="RemainD"></strong><strongid="RemainH">XX</strong>时<strongid="RemainM">XX</strong>分<strongid="RemainS">XX</strong>秒<inputid="Button1"type="button"value="button"onclick="takeCount()"/></div></div></form></body></html>
解决方案三:
谢谢拉,不过你回答的不是我想要的答案,setInterval("checkisnew()",'时间');这个时间不能是变量吗???
解决方案四:
每人回话吗???人哪去拉
解决方案五:
可以是变量。<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="aa.aspx.cs"Inherits="aa"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>无标题页</title><scripttype="text/javascript">vari=1;functionabc(){i++;vart=document.getElementById("txtabc").value;document.getElementById("spabc").innerHTML=i;setInterval("abc()",t);}</script></head><body><formid="form1"runat="server"><div><spanid="spabc">1</span><inputid="txtabc"type="text"/><inputid="Button2"type="button"onclick="abc()"value="button"/></div></form></body></html>
我测试好的
解决方案六:
前面的弄错,setInterval改成setTimeout
解决方案七:
为什么我必须要alert('字符串');才会执行setInterval("checkisnew()",t);页面:alert('字符串');vart=document.getElementById("Hid_ms").value;//Hid_ms这是一个隐藏域,值是通过后台动态赋值给他setInterval("checkisnew()",t);后台代码://这是一个DropDownListprotectedvoidddl_ms_SelectedIndexChanged(objectsender,EventArgse){stringms=this.ddl_ms.SelectedValue.ToString();this.Hid_ms.Value=ms;}
解决方案八:
alert('字符串');vart=document.getElementById("Hid_ms").value;//Hid_ms这是一个隐藏域,值是通过后台动态赋值给他setInterval("checkisnew()",t);你也并没有证据说明setInterval("checkisnew()",t);已经执行了vart=document.getElementById("Hid_ms").value;//Hid_ms这是一个隐藏域,值是通过后台动态赋值给他setInterval("checkisnew()",t);alert('字符串');你这样试试看
解决方案九:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="setInterval.aspx.cs"Inherits="setInterval"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>无标题页</title><scripttype="text/javascript">vari=1;vars;functionabc(){i++;document.getElementById("spabc").innerHTML=i;if(i==100){clearInterval(s);}}functiona(){vart=document.getElementById("txtabc").value;s=setInterval("abc()",t);}</script></head><body><formid="form1"runat="server"><div><spanid="spabc">1</span><inputid="txtabc"type="text"/><inputid="Button2"type="button"onclick="a()"value="button"/></div></form></body></html>
解决方案十:
还想问一个问题::为什么重新加载表之后,表的样式没起作用??<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="index.aspx.cs"Inherits="index"%><%@RegisterAssembly="System.Web.Extensions,Version=1.0.61025.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI"TagPrefix="asp"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>BetHistory</title><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><linktype="text/css"rel="Stylesheet"href="css.css"/><scriptlanguage="javascript"type="text/javascript">window.onerror=function(){returntrue;//不显示脚本错误信息}</script><scriptlanguage="javascript"type="text/javascript"defer="defer">function_start(){bgsound.src="sound/msg.wav";}function_stop(){bgsound.src="";}varbuMenClassID=<%Response.Write(checkdata());%>;//取出最新的ID值varbuCount=<%Response.Write(checkdata2());%>;//取出最新数据记录条数vart=<%Response.Write(Session["ms"].ToString());%>setInterval("checkisnew()",t);functioncheckisnew(){//varres=index.checkdata();//varnewBuMenClassID=res.value;varre2=index.checkdata2();varnewbuCount=re2.value;//如果最新取到的值和页面加载时取到的值不一样,即数据库已更新,重新更新页面//if(buMenClassID!=newBuMenClassID)if(buCount!=newbuCount&&buCount<newbuCount){DeleteTableRow();tdvalue();for(i=1;i<=newbuCount-buCount;i++){tb1.rows[i].className="t1";}_start();buCount=newbuCount;}}//删除tb1中的所有行functionDeleteTableRow(){varaa=tb1.rows.length;for(vari=aa-1;i>0;i--){tb1.deleteRow(i);}}//重新加载tablefunctiontdvalue(){varres=index.GetBetHistory("").value;for(varo=0;o<res.length;o++){//添加一行varnewTr=tb1.insertRow();//添加两列varnewTd1=newTr.insertCell();varnewTd2=newTr.insertCell();//设置列内容和属性newTd1.innerText=res[o].bettime;newTd2.innerText=res[o].userid;}}</script></head><body><formid="form1"runat="server"><divstyle="margin:7px;"><tableid="tb1"width="100%"border="0"cellpadding="0"cellspacing="1"bordercolor="#333333"bgcolor="#b7b7b7"><tr><tdwidth="0"height="25"align="center"bgcolor="#3366CC"class="txt_top">ID</td><tdwidth="0"align="center"bgcolor="#3366CC"class="txt_top">時間</td><tdalign="center"bgcolor="#3366CC"class="txt_top">用戶</td></tr><asp:RepeaterID="Repeater1"runat="server"EnableViewState="false"><ItemTemplate><trstyle="border:solid1px#000000;"id="<%#Eval("ID")%>"><tdalign="center"bgcolor="#f9f9f9"><%#Eval("BetTime")%></td><tdalign="center"bgcolor="#f9f9f9"><%#Eval("UserID")%></td><tdalign="center"bgcolor="#f9f9f9"><%#Eval("AgentSite")%></td></tr></ItemTemplate></asp:Repeater></table></div></form></body></html>