如果数字为<=
0,我正试图隐藏按钮。
我的代码:
<?php
$sst = $user->runQuery("SELECT * FROM students_records WHERE LRN=:uID AND SRN=:sd");
$sst->bindparam(":uID",$id);
$sst->bindparam(":sd",$srn);
$sst->execute();
$sstRow=$sst->fetch(PDO::FETCH_ASSOC);
$dsst = $sstRow['Date'];
$sdsst = strtotime($dsst);
echo "
<script>
var checkStatet = function(){
jQuery.ajax({
url: 'q_check_diffex.php?od=$sdsst'
}).done(function(data){
var button1 = jQuery('#rbtntimep');
var o = data.diffex;
var time = jQuery('#rbtntime');
var timer = setInterval(function() {
time.html(o);
o--;
if(data.diffex <= 0) {
button1.hide();
jQuery('#quizsb').click();
}
}, 1000)
});
}
checkStatet();
</script>
"
?>
<button class="btn btn-large btn-primary" id="rbtntimep" style="float:right;" disabled><span id="rbtntime"></span></button>
q_check_diffex.php :
<?php
header('Content-Type: application/json');
if(isset($_GET['od'])){
$deotd = $_GET['od'];
}
date_default_timezone_set('Asia/Calcutta');
$cdate = date('Y-m-d H:i:s ', time());
$scdate = strtotime($cdate);
$rscdate = $scdate + 10;
$e = $rscdate - $deotd;
// You would calculate a real value here
echo json_encode([
'diffex' => $e
]);
?>
我尝试了上面的代码但是如果<=
0
答案 0 :(得分:0)
您将从q_check_diffex.php获取JSON中的响应
因此,在使用var o = data.diffex;
之前,您需要将响应转换为对象。
只需在done(function(data){
data = JSON.parse(data);
现在,您可以在代码var o = data.diffex;