【发布时间】:2012-07-25 03:42:55
【问题描述】:
我有一个 php 程序,它将计算时间差并以分钟为单位返回值。
对于消息弹出我使用jGrowl
所以我想做的是获取返回值,如果它少于 30 分钟显示 jquery 消息。
最重要的是它应该实时运行。因此,如果用户在没有导航或刷新的情况下进入页面,如果时间少于 30 分钟,则弹出窗口应实时显示。
有人可以建议我如何使用返回值来实现上述要求吗?
下面是我用来计算时差的代码
function time($dbtime, $currtime)
{
//format year-month-day hour:min:secs
$current = strtotime($currtime);
$indb = strtotime($dbtime);
$minits = round(abs($current - $indb) / 60,2);
return $minits;
}
目前我只弹出日期的消息
<script type="text/javascript">
(function($){
$(document).ready(function(){
// jGrowl
if ($.fn.jGrowl) {
// This value can be true, false or a function to be used as a callback when the closer is clciked
$.jGrowl.defaults.closer = function() {
console.log("Closing everything!", this);
};
// A callback for logging notifications.
$.jGrowl.defaults.log = function(e,m,o) {
$('#logs').append("<div><strong>#" + $(e).attr('id') + "</strong> <em>" + (new Date()).getTime() + "</em>: " + m + " (" + o.theme + ")</div>")
}
<?php foreach ($dailies as $daily):?>
$.jGrowl("<?php echo $daily['calendars'][0]['Title']?>", { header: 'At <?php echo $daily['calendars'][0]['Start'];?>', sticky: true });
<?php endforeach;?>
$.jGrowl.defaults.closerTemplate = '<div>hide everything</div>';
}
});
})(jQuery);
</script>
【问题讨论】:
-
有单独的PHP页面返回JSON(使用
json_encode),然后使用响应对象做任何你想做的事! -
@MrOBrian 我已经添加了代码..
-
@MaX 你能再解释一下吗?
-
我没有看到任何代码在那里您正在检查一个值并在它符合条件时显示一条消息。你在哪里节省过去的时间,你在哪里检查它?看起来你没有在任何地方调用你的
time函数。 -
@MrOBrian 时间函数返回分钟并且可以通过 $alarm->timediffn 访问。其实你问我的就是我在问题中问的。问题是我不知道如何使用返回值进行实时弹出。我想知道如何实时检查。