【问题标题】:jquery how to show alert based on datetime picker value?jquery如何根据日期时间选择器值显示警报?
【发布时间】:2016-08-31 18:23:37
【问题描述】:

我有一个 Laravel 4.2 / PHP 项目,它有一个在页面加载时显示的模式,我的表单中有一个日期时间选择器。如果日期在当前日期的 30 天内或更短的时间内,我希望弹出警报。当我尝试在 datepicker 中编写某些内容时,模态函数消失并且选择器恢复到正常状态。有人可以给我一些关于如何解决这个问题的指导吗?

  $('#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 输入更改事件中做一个 DateDiff 吗?

标签: javascript php jquery laravel datetime


【解决方案1】:

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

使用 jQuery:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 2012-09-11
    • 1970-01-01
    相关资源
    最近更新 更多