[已解决问题]
解决于 2008-01-14 09:26
<P><EM> 页面中有两个文本框控件,ID分别为txtFrom和txtTo。分别在两个框中输入两个日期:2008-01-08和2007-01-07,调用下面的脚本代码。</EM></P>
<P><EM></EM> </P>
<P><EM>function CheckFromToControl(id)<BR>{<BR> // 取得开始控件<BR> var from = document.all(id);<BR> <BR> // 取得截至控件<BR> var to = document.all(id.replace("txtFrom", "txtTo"));<BR> var fromVal = from.value;<BR> var toVal = to.value;<BR> if (ChkNull(fromVal) && ChkNull(toVal))<BR> {<BR> var fromDate = new Date(fromVal);<BR> var toDate = new Date(toVal);<BR> if (fromDate > toDate)<BR> {<BR> to.style.backgroundColor = "#FF0000";<BR> alert("起始时间不能大于终止时间!");<BR> to.focus();<BR> return false;<BR> }<BR> alert(fromDate != toDate);<BR> alert(fromDate == toDate);<BR> alert(fromDate > toDate);<BR> alert(fromDate < toDate);<BR> }<BR> to.style.backgroundColor = "#FFFFFF";<BR> return true;<BR>}</EM></P>
<P><EM></EM> </P>
<P><EM>分别弹出的四个框的文本分别是:</EM></P>
<P><EM>true</EM></P>
<P><EM>false</EM></P>
<P><EM>false</EM></P>
<P><EM>false</EM></P>
<P><EM></EM> </P>
<P><EM>对应代码:</EM></P>
<P><EM>alert(fromDate != toDate);<BR> alert(fromDate == toDate);<BR> alert(fromDate > toDate);<BR> alert(fromDate < toDate);<BR></EM></P>
<P><EM>真实怪事,难道fromDate不等于toDate,fromDate不大于toDate,fromDate不小于toDate。那么fromDate和toDate是什么样的路基关系?</EM></P>
<P><EM></EM> </P>
问题补充:
修改一下javascript:
function CheckFromToControl(id)
{
// 取得开始控件
var from = document.all("txtFrom",);
// 取得截至控件
var to = document.all("txtTo");
var fromVal = from.value;
var toVal = to.value;
var fromDate = new Date(fromVal);
var toDate = new Date(toVal);
if (fromDate > toDate)
{
to.style.backgroundColor = "#FF0000";
alert("起始时间不能大于终止时间!");
to.focus();
return false;
}
alert(fromDate != toDate);
alert(fromDate == toDate);
alert(fromDate > toDate);
alert(fromDate < toDate);
to.style.backgroundColor = "#FFFFFF";
return true;
}
荣-
|
初学一级
|
园豆:
25
提问于:2008-01-08 17:52