bootstrap datepicker无法设置minDate

时间:2016-05-29 20:09:56

标签: javascript twitter-bootstrap-3 bootstrap-datetimepicker

我做了很多修改,我尝试了许多不同的东西,但没有任何作用。我有一个isabled字段,其中包含日期(25-05-2016)。我想用这个值(25-05-2016)将minDate设置为我的datepicker。 即使我直接设置了值,也没有任何作用。这是我的代码:

var myDate = $('#CRUEventModal #rdvStartDate').val(); //Get the value from field
myDate = moment(myDate , "DD-MM-YYYY");
//myDate  = moment(myDate , "DD-MM-YYYY").add(1, 'months'); one of things i tried

var myDate2 = $('#CRUEventModal #rdvStartDate').val(); // Another things i tried
myDate2 = moment(myDate2 , "DD-MM-YYYY").format('YYYY-MM-DD');

$('#rdvFinDatefinPicker')
    .datepicker({
        useCurrent: false, //Important! See issue #1075
        format: 'dd-mm-yyyy',
        language:"fr",
        autoclose:"true",
        minDate: myDate  //myDate2 didn't work too!
    })
    .on('changeDate', function(e) {
        // Revalidate the date field
        //$('#eventForm').formValidation('revalidateField', 'eventDate');
    });

非常感谢

3 个答案:

答案 0 :(得分:1)

$('#rdvFinDatefinPicker')
        .datepicker({
            useCurrent: false, //Important! See issue #1075
            format: 'dd-mm-yyyy',
            **startDate: '28-05-2016',**
            language:"fr",
            autoclose:"true",

        })

你应该使用startdate函数,这是你想要的日期开始或enddate函数也有助于maxdate ... thnaks

答案 1 :(得分:0)

使用eonasdan datetimepicker,您可以拥有以下代码:

var myDate = $('#rdvStartDate').val(); //Get the value from field
myDate = moment(myDate , "DD-MM-YYYY");

$('#rdvFinDatefinPicker')
    .datetimepicker({
        useCurrent: false, //Important! See issue #1075
        format: 'DD-MM-YYYY',
        locale:"fr",
        minDate: myDate
    })
    .on('dp.change', function(e) {
        // Revalidate the date field
        //$('#eventForm').formValidation('revalidateField', 'eventDate');
    });
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/locale/fr.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>

<input id="rdvStartDate" type='text' class="form-control" value="25-05-2016" disabled />
<div class='input-group date' id='rdvFinDatefinPicker'>
  <input type='text' class="form-control" />
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>

请注意,您必须为momentjs导入法语区域设置并设置locale选项。格式选项必须遵循momentjs rules,因此您必须将其指定为大写。您不需要autoclose选项,因为datetimepicker默认情况下false选项为[Theory ] [AutoData] public void ShouldBeSum_AutoData(int a, int b, Sum uut ) { //problem int residue = uut.Value; //not zero! //fix uut.Value = 0; //Arrange - in the parameter leads to problem // var uut =new Sum(); //Act uut.Add(a); uut.Add(b); //Assert Assert.Equal(a + b, uut.Value); }

请注意,datetimepicker会触发keepOpen

我更喜欢eonasdan datetimepicker,因为它使用了momentjs并且它有一个丰富的API。

答案 2 :(得分:0)

**$('#datetimepicker1').datetimepicker({
           // format: 'dddd, MMMM Do YYYY, h:mm:ss a',
            format: "dd-M-yyyy, HH:ii P",
            startDate: '+1d',
            endDate: '+60m',
            showMeridian: true,
            autoclose: true
        });      

否则

$('#datetimepicker1').datetimepicker({
       format: 'dddd, MMMM Do YYYY, h:mm:ss a',
       useCurrent: false,
       minDate: moment().add(1, 'd').toDate(),

       locale: 'de',

     });
   });

记住添加你想要开始的一天..我希望它会被使用它 我在项目中使用的第一个代码......它运行良好,。