[英]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">×</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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.