Jquery如何显示警报基于日期时间选择器的值


jquery how to show alert based on datetime picker value?

我有一个Laravel 4.2/PHP项目,它有一个模式,显示在页面加载,我有一个日期时间选择器在我的形式。我想有一个警报弹出,如果日期是在30天或更少的当前日期。当我尝试在日期拾取器中编码一些东西时,模态函数消失,拾取器恢复到正常状态。有人能给我一些指导如何解决这个问题吗?

  $('#myModal').modal('show');
    $('#ApplicationDeadline').datepicker({
        startDate: '1d',
        endDate: '+365d',
'' code for alert goes here I assume? When I put code here it breaks the modal 
      });

    @if($Modal)
         <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" >
          <div class="modal-dialog">
              <div class="modal-content">
                 <div class="modal-header">
                     <button type="button" class="close" data-dismiss="modal">
                         <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                     </button>
                     <h4 class="modal-title">External Grant</h4>
                 </div>
                 <div class="modal-body">
                     <p>The External Grant Pro Application needs to be discussed with Grant Administrator before submitting an application. </p>
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-primary btn-lg pull-right" data-dismiss="modal">OK, Let's Begin</button>
                 </div>
           </div>
       </div>
    </div>
    @endif
    {{ HTML::col(6,6,6,6) }}
        {{ Form::formGroup() }}
            {{ Form::label('ApplicationDeadline', 'Application Deadline Date') }}
            {{ Form::date('ApplicationDeadline', '', array('class' => 'form-control')) }}
        {{ Form::closeFormGroup() }}
    {{ HTML::closeCol() }}

您的函数需要作为事件侦听器的回调调用。如果希望在datepicker对象中指定更改事件回调,则必须咨询API。否则,使用jQuery,一个普通的事件监听器就可以了。

使用jQuery:

<script>
...
    $(function() {
        $('#ApplicationDeadline').on('change', function(){
           // datediff / alert code here
        });
    });    
...
</script>