jQuery中的日期比较 [英] Date comparison in Jquery

查看:96
本文介绍了jQuery中的日期比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较所选日期和当前日期. IAM使用jQuery日期选择器.在使用以下代码时,仅进行日期字段比较...我如何也可以与月份和年份进行比较...提前谢谢..

I want to compare the selected date and current date. Iam using jquery date picker. While using the following code only the date field comparison is takes place... How can i compare with month and year also... Advance thanks..

$(document).ready(function() {



        var objDate = new Date();
        var selectedDate = document.getElementById("<%=txtRqstDate.ClientID %>").value;

        var currentDate = $.datepicker.formatDate('dd/mm/yy', new Date());
        if (Date.parse(selectedDate) > Date.parse(currentDate )) {
            alert("Invalid date range!\n Please choose a date that is not later than today!")
            return false;
        }
        else {
            return true;
        }

推荐答案

请使用此功能.我认为这可以解决您的问题

Pls use this.I thing it will solve ur problem

function ChDate(){
 var objDate = new Date();
 var selectedDate = document.getElementById("<%=txtRqstDate.ClientID %>").value;

if (selectedDate > objDate ) {
  //do
}
else
{
 //do
}
}

请点击以下链接以获取更多功能 http://www.w3schools.com/jsref/jsref_obj_date.asp 可以通过使用string.split(separator,limit)

Pls chk the following link to get more functions http://www.w3schools.com/jsref/jsref_obj_date.asp It is possible to take split an do checking by using string.split(separator, limit)

这篇关于jQuery中的日期比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆