【发布时间】:2018-10-24 23:22:12
【问题描述】:
我的代码应该减去日期(enddate-startdate),但什么也没发生,也无法弄清楚问题出在哪里。
<script type="text/javascript">
function subtractDate()
{
var sDate = Date.parse("<%=txtStartDate.Text%>");
var eDate = Date.parse("<%=txtEndDate.Text%>");
var resultDate = document.getElementById("<%=txtnumberOfDaysCovered.ClientID%>")
if (document.getElementById(sDate) < document.getElementById(eDate)) {
var timeDiff = eDate.Subtract(sDate);
resultDate = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
}
}
</script>
我已经尝试在后面调用它
protected void txtStartDate_TextChanged(object sender, EventArgs e)
{
// SubtractDateStartDateChange();
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "subtractDate(this.Id)", true);
}
protected void txtEndDate_TextChanged(object sender, EventArgs e)
{
//SubtractDate();
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "subtractDate(this.Id)", true);
}
【问题讨论】:
-
请忽略最后一句话
-
你可以edit你的问题。
-
您不会对
subtractDate计算的结果做任何事情。因此什么也没有发生。 -
什么都不会发生,因为你只是计算 resultDate 而不是在任何地方使用它
-
"<%=txtStartDate.Text%>"返回的值是多少?希望您知道使用内置解析器的陷阱,请参阅Why does Date.parse give incorrect results?
标签: javascript c# asp.net date