JQuery DatePicker on ASP.net

后端 未结 3 1129
心在旅途
心在旅途 2021-01-26 21:34

Well,

Im trying to put Date Picker on ASP.net form..

I saw that this code can do it..



        
3条回答
  •  一生所求
    2021-01-26 22:11

    I pulled out my code for this. The code is self explanatory if you know jQuery/Javascript.

     var dateToday = new Date();
     var fromDate = (dateToday.getMonth() + 1) + "/" + dateToday.getDate() + "/" +    dateToday.getFullYear()
     var toDate = (dateToday.getMonth() + 1) + "/" + dateToday.getDate() + "/" + dateToday.getFullYear()
    

    // Initialize FromDate

     $('#datepicker1').datepicker({
        todayBtn: "linked",
        multidate: false,
        autoclose: true,
        todayHighlight: true
     });
    

    // Handle fromDate Click

    $('#datepicker1').datepicker('setDate', fromDate);
    
    $('#datepicker1').datepicker().on('changeDate', function (e) {
        fromDate = $('#datepicker1').val().toString();
        if (fromDate > toDate) {
            toDate = fromDate;
            $('#datepicker2').datepicker('setDate', toDate);
        }
    });
    

    // Initialize toDate

    $('#datepicker2').datepicker({
        todayBtn: "linked",
        multidate: false,
        autoclose: true,
        todayHighlight: true
    });
    

    //Handle toDate Click

    $('#datepicker2').datepicker('setDate', toDate);
    
    $('#datepicker2').datepicker().on('changeDate', function (e) {
        toDate = $('#datepicker2').val().toString();
        if (toDate < fromDate) {
            fromDate = (new Date(toDate).getMonth() + 1) + "/01/" + new Date(toDate).getFullYear();
            $('#datepicker1').datepicker('setDate', fromDate);
        }
    });
    

    I forgot to mention that am using this https://github.com/eternicode/bootstrap-datepicker/blob/release/docs/index.rst

提交回复
热议问题