我想在C#后面的代码中访问变量sec和min进行一些验证 。由于sec和min是动态变化的,使用隐藏字段存储它然后在C#中访问它是好的吗?
`var sec = 15; var min = 100;
var counter=setInterval(timer, 1000); //1000 will run it every 1 second
function timer()
{
sec=sec-1;
if(sec < 0)
{
sec=59;
min--;
}
else
{
min=min;
}
if(sec <=9 ){
sec = "0"+sec;
}
document.getElementById("lblCountDown").innerHTML= "Time Left: "+(min<=9 ? "0" + min : min)+" mins"+" "+sec + " secs";`
答案 0 :(得分:0)
如果您愿意,请使用此功能。在服务器端获取Request.Form["min"]
<input type="hidden" id="min" name="min"/>
<input type="hidden" id="sec" name="sec"/>
在Javascript上:
...
document.getElementById("lblCountDown").innerHTML= "Time Left: "+(min<=9 ? "0" + min : min)+" mins"+" "+sec + " secs";`
document.getElementById("min").value=min;
document.getElementById("sec").value=sec;
记住这是更糟糕的主意