从数据库中取值,传到前台,倒计时程序,值传过来之后,不能运算还是其他原因,u_time不显示,innertext=docment.get......能显示出来,
aspx页面:
<script type="text/javascript">
var sec = document.getElementById('<%=xx.ClientID %>').value ;
var min = document.getElementById('<%=yy.ClientID %>').value ;
var hou = document.getElementById('<%=zz.ClientID %>').value ;
window.setInterval("ls();", 1000);
function ls() {
sec--;
if (sec <= 0) { sec = 59; min--; }
if (min <= 0) { min = 59; hou--; }
document.getElementById("u_time").innerText = hou + "时" + min + "分" + sec + "秒";
}
</script>
<body>
<input id="xx" type="hidden" runat="server" />
<input id="yy" type="hidden" runat="server" />
<input id="zz" type="hidden" runat="server" />
cs页面:
DateTime d1 = Convert.ToDateTime(dr["time1"]);
DateTime d2 = Convert.ToDateTime(dr["time2"]);
DateTime dt1 = DateTime.Now;
System.TimeSpan dx = d2.Subtract(dt1);
string hou = dx.Hours.ToString();
string min = dx.Minutes.ToString();
string sec = dx.Seconds.ToString();
xx.Value = sec;
yy.Value = min;
zz.Value = hou;
var sec = document.getElementById('<%=xx.ClientID %>').value ;
var min = document.getElementById('<%=yy.ClientID %>').value ;
var hou = document.getElementById('<%=zz.ClientID %>').value ;
把这三个放到ls()方法里面
关键我还有这句window.setInterval("ls();", 1000),放进去后sec min hou都不变了吧。
@mmypdf: 你也可以把整个javascript放到
<input id="xx" type="hidden" runat="server" />
<input id="yy" type="hidden" runat="server" />
<input id="zz" type="hidden" runat="server" />
的后面。或者用window.onload里面来获取这三个值
var sec = document.getElementById('<%=xx.ClientID %>').value ;
var min = document.getElementById('<%=yy.ClientID %>').value ;
var hou = document.getElementById('<%=zz.ClientID %>').value ;
@mmypdf: 原因应该是,var sec获取值的时候,你xx的这个input还不存在
@单恋: 放后边能执行了,不过window.onload怎么获取值,这样吗
window.onload = function () {
var sec = document.getElementById('<%=xx.ClientID %>').value;
var min = document.getElementById('<%=yy.ClientID %>').value;
var hou = document.getElementById('<%=zz.ClientID %>').value;
}//
window.onload = function () {
var sec = document.getElementById('<%=xx.ClientID %>').value;
var min = document.getElementById('<%=yy.ClientID %>').value;
var hou = document.getElementById('<%=zz.ClientID %>').value;
window.setInterval("ls();", 1000);
function ls() {
sec--;
if (sec <= 0) { sec = 59; min--; }
if (min <= 0) { min = 59; hou--; }
document.getElementById("u_time").innerText = hou + "时" + min + "分" + sec + "秒";
}
}
这两种都不行,刚学的,问问,多知道点......
@mmypdf:
http://blog.csdn.net/kk5595/article/details/5713209 onload这个我也很少用。一般都引用jquery中的$.ready()来做。你看一下上面那边博客嘛。
不过,我觉得应该是这样的(没测试过)。
var sec,min,hou;
window.onload = function () {
sec = document.getElementById('<%=xx.ClientID %>').value;
min = document.getElementById('<%=yy.ClientID %>').value;
hou = document.getElementById('<%=zz.ClientID %>').value;
}
window.setInterval("ls();", 1000);
function ls() {
sec--;
if (sec <= 0) { sec = 59; min--; }
if (min <= 0) { min = 59; hou--; }
document.getElementById("u_time").innerText = hou + "时" + min + "分" + sec + "秒";
}