0

我有以下代码和验证来检查输入的日期是否有效。我需要添加一些简单的 javascript 验证来检查“到期”日期是否早于“审阅”日期。如果到期日期是审查日期之前的日期,则可以,如果没有,则给出错误警报框。谢谢你的帮助。

我想我可以比较这两个字符串,看看一个是 < 还是另一个,但不确定最好的方法是什么。

<tr>
    <td class="SubHeader" height="5%">Review</td>
</tr>
<tr>
<td class="Label">Review By</td>
<td>
    <input class="amdInputText" type="text" id="guaranteereviewbydate" value="">
    <xsl:attribute name="value"><xsl:value-of select="guaranteereviewbydate"/></xsl:attribute>
    </input>
</td>
</tr>
<tr>
<td class="Label">Expire On</td>
<td><input class="amdInputText" type="text" id="guaranteeexpireondate" value="">
    <xsl:attribute name="value"><xsl:value-of select="guaranteeexpireondate"/></xsl:attribute>
    </input>
</td>
</tr>

<xsl:if test="count(../bankguaranteedata) &gt; '1'">
else if(!validateDate(document.lending.guaranteereviewbydate[<xsl:value-of select="@id"/>].value)){alert("Please enter a valid review by date. The date must be of the format dd/mm/yyyy");document.lending.guaranteereviewbydate[<xsl:value-of select="@id"/>].focus();return false;}                                  
else if(!validateDateExpireOn(document.lending.guaranteeexpireondate[<xsl:value-of select="@id"/>].value)){alert("Please enter a valid expire on date. The date must be of the format dd/mm/yyyy");document.lending.guaranteeexpireondate[<xsl:value-of select="@id"/>].focus();return false;}
</xsl:if>


<xsl:if test="count(../bankguaranteedata) = '1'">
else if(!validateDate(document.lending.guaranteereviewbydate.value)){alert("Please enter a valid review by date. The date must be of the format dd/mm/yyyy");document.lending.guaranteereviewbydate.focus();return false;}                                  
else if(!validateDateExpireOn(document.lending.guaranteeexpireondate.value)){alert("Please enter a valid expire on date. The date must be of the format dd/mm/yyyy");document.lending.guaranteeexpireondate.focus();return false;}
</xsl:if>
4

2 回答 2

1

您需要将数据字符串转换为 JavascriptDate对象,并使用普通运算符<>.

于 2013-03-04T12:33:55.923 回答
0

使用您的上述回复,我已将代码修改如下:

<xsl:if test="count(../documentarycreditdata) &gt; '1'">                
else if(!compareDates(document.lending.documentaryexpireondate[<xsl:value-of select="@id"/>].value, document.lending.documentaryreviewbydate[<xsl:value-of select="@id"/>].value)){alert("Please enter an expire on date which is later than the review by date");document.lending.documentaryexpireondate[<xsl:value-of select="@id"/>].focus();return false;}
</xsl:if><xsl:if test="count(../documentarycreditdata) = '1'">          
else if(!compareDates(document.lending.documentaryexpireondate.value, document.lending.documentaryreviewbydate.value)){alert("Please enter an expire on date which is later than the review by date");document.lending.documentaryexpireondate.focus();return false;}
</xsl:if>

 function compareDates(expirydate, reviewbydate){
 if(expirydate.length <11 && reviewbydate.length <11)
    {
try{
  dayexpire = expirydate.substring(0,2);
  monthexpire = expirydate.substring(3,5);
  yearexpire = expirydate.substring(6,10);
  dayreview = reviewbydate.substring(0,2);
  monthreview = reviewbydate.substring(3,5);
  yearreview = reviewbydate.substring(6,10);
  totalexpire = expirydate.substring(3,5)+"/"+expirydate.substring(0,2)+"/"+expirydate.substring(6,10);
  totalreview = reviewbydate.substring(3,5)+"/"+reviewbydate.substring(0,2)+"/"+reviewbydate.substring(6,10);
  newexpirydate = new Date(totalexpire);
  newreviewdate = new Date(totalreview);
  if(newexpirydate < newreviewdate)
     {
       return false;
     }
  else
     return true;
}catch(e){return false;}
 }
 else
 return false;

}

日期作为字符串传入,并以新 Date() 接受的 mm/dd/yyyy 格式输入

然后我进行比较并工作。

于 2013-03-04T15:46:28.213 回答