下面的代码:if(exDate.isBefore(今天)||!exDate)->!exDate代码不起作用。谁能帮我?我正在尝试根据到期日期计算ef FEE。 http://verlager.com/account-pure.php该代码必须包含**成员>“” **
function calcEntryFee( elem ) {
var idx, member, exDate, today, fee;
elem = elem || {};
if ( /^[PEMX](\d+)$/.test( elem.id ) ) {
idx = RegExp.$1;
} else {
return false;
}
member = getMemberData( jQuery( '#P' + idx ).val() );
mmfee = parseFloat( jQuery( '#M' + idx ).val() );
//exDate = moment( member.Expires, 'YYYY.MM.DD' );
exDate = member && member.Expires && member.Expires !== '' ? moment( member.Expires, 'YYYY.MM.DD' ) : null
today = moment();
fee = '';
if ( (!exDate || !exDate.isValid() || exDate.isBefore( today )) && (member.Name > '')) {fee = 5;} // this just doesn't work.
if (!exDate)
{
fee = 5;
} else if ( exDate.isSameOrAfter( today ) ) {
fee = 3;
} else if ( ! member.Expires && mmfee > 0 ) {
fee = 0;
}
// Updates the entry fee input value.
jQuery( '#E' + idx ).val( fee );
return fee;
}
最佳答案
我有这个确切的问题。我最终使用了moment-range。根据您的代码示例,也许您可以像这样检查过期时间:
import Moment from 'moment'
import { extendMoment } from 'moment-range'
const moment = extendMoment(Moment)
export default (expires) => {
const momentExpires = moment(expires, 'YYYY.MM.DD')
const now = moment()
const expirationCheck = moment.range(now.format(), momentExpires.format())
return {
expired: expirationCheck.valueOf() < 0
}
}