简体   繁体   English

datetimepicker无法正常工作

[英]datetimepicker is not working correctly

I have created one custom control for datetime picker in one control i have given three mode datetimepicker,timepicker and datepicker.For which i have created one property called CalenderMode of type enum which stores these three modes and which value i am given to the property according to that i am changing the datetimepicker,if i given timepicker then my timepicker is enabled,if i give datepicker then date picker is enabled and if i give datetimepicker then my datetimepicker is enabled this i am handling in jquery. 我在一个控件中为日期时间选择器创建了一个自定义控件,我给了三种模式datetimepicker,timepicker和datepicker。为此,我创建了一个名为CalenderMode的属性,该属性存储了这三种模式,并根据属性将值赋予了我我正在更改datetimepicker,如果我给了timepicker然后启用了我的时间选择器,如果我给了datepicker然后启用了日期选择器,如果我给了datetimepicker然后启用了我的datetimepicker这是我在jquery中处理的。

For validation of these i am given format from c# and that format i am using in client side but now problem is if my timepicker or date picker is enabled and from timepicker i am selecting time but in text box it showing date time this is same for the date picker also there also it is showing date time. 为了验证这些,我从c#中获得了格式,并且在客户端使用了该格式,但是现在的问题是是否启用了我的时间选择器或日期选择器,并且从时间选择器中我选择了时间,但是在文本框中它显示了日期时间,对于日期选择器也在那里也显示日期时间。

Here i am not understanding what is the issue. 在这里我不明白是什么问题。

My code of jquery where i am changing the mode of calender using assigning the value to property is 我通过将值分配给属性来更改日历模式的jQuery代码是

$(document).ready(function () {
$('.calendercssclass').each(function () {
    var result;
    var value = $(this).closest('.DateControl').find("input[type=hidden][id*='CalenderTypeModeID']").val();
    if (value == "timepicker") {
        $(this).datetimepicker({
            timepicker: true,
            datepicker: false
            //mask: true
        });
    }
    else if (value == "datepicker") {
        $(this).datetimepicker({
            timepicker: false,
            datepicker: true
            // mask: true
        });
    }
    else {
        $(this).datetimepicker({
            //mask: true
        });
    }
});

}); });

To give the format for validation i am using following code 为了给出验证格式,我正在使用以下代码

function ValidateFormatOfDatecontrol(sender, args) {
debugger;
args.IsValid = true;
var format;
$('.calendercssclass').each(function () {
    var result;
    var value = $(this).closest('.DateControl').find("input[type=hidden][id*='CalenderTypeModeID']").val();
    if (value == "timepicker") {
        format = $(this).closest('.DateControl').find("input[type=hidden][id*='ClientTimeFormatID']").val();

        var answer = $(this).val();
        if (answer != '') {
            //Moment.js inbuilt function for validating the date format . 
            args.IsValid = moment(answer, format, true).isValid();


        }
    }
    else if (value == "datepicker") {
        format = $(this).closest('.DateControl').find("input[type=hidden][id*='ClientDateFormatID']").val();
        var answer = $(this).val();

        if (answer != '') {
            //Moment.js inbuilt function for validating the date format . 
            args.IsValid = moment(answer, format, true).isValid();
        }
    }
    else if (value == "datetimepicker") {
        format = $(this).closest('.DateControl').find("input[type=hidden][id*='ClientDateTimeFormatID']").val();
        var answer = $(this).val();

        if (answer != '') {
            //Moment.js inbuilt function for validating the date format . 
            args.IsValid = moment(answer, format, true).isValid();


        }
    }
});

} }

server side code for giving format for validation is 提供验证格式的服务器端代码是

 this.clientDateFormat.Value = "MM/DD/YYYY";
 this.clientDateTimeFormat.Value = "mm/dd/yyyy H:i A";
 this.clientTimeFormat.Value = "H:i";

Screenshot for issue is 该问题的屏幕截图为

在此处输入图片说明

Can anybody help me for this? 有人可以帮我吗?

Here You are using Rain Jquery so fromat of Rain for the time is different from the moment what you are using for the validation so following is the format for both 在这里,您正在使用Rain Jquery,因此,来自Rain的时间与您用于验证的时间有所不同,因此以下是两者的格式

Rain Jquery Time Format : h:i A Moment Time Format : h:mm A Rain Jquery时间格式: h:i A时间格式: h:mm A

Following is the sample code 以下是示例代码

Script 脚本

 $(document).ready(function () { 
    $(".date").datetimepicker({
        format: 'h:i A',            
        datepicker:false
    });

    $(".date").change(function () {
        var format = "h:mm A";
        $('#message').text(moment($(".date").val(), format, true).isValid());
    });

    });

Markup 标记

<div>
    <asp:TextBox ID="TextBox1" runat="server" CssClass="date"></asp:TextBox>

    <asp:Label ID="message" runat="server" CssClass="message"></asp:Label>


</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM