在过期时禁用按钮


disable button when it expires

如果优惠券已经下载或过期,我有一个按钮当前会提醒用户。我该如何实现,以便在它过期时,它不会返回警报,而是禁用按钮?目前以下是我的按钮。

<?php
    if (isset ( $entry["couponId"] )) { 
    if(! isset($_SESSION["loginSuccess"])) { ?>
    <button type="submit" value="Coupon" class="disabledbuttonlink" id="couponButton-<?php echo $entry['id']; ?>">Log in to download</button>
    <?php
    } else {
?>
    <button type="submit" value="Coupon" class="buttonlink" id="couponButton-<?php echo $entry['id']; ?>">Coupon</button>
<?php } }?>

下面是我的脚本

<script type="text/javascript">
<?php
    foreach($resultAllPosts['lists'] as $entry){?>
        $('#couponButton-<?php echo $entry['id']; ?>').click(function(){
            if ("<?php echo $sessionId?>" == "<?php echo $non_login_user?>") {
            alert("Please log in to download coupons");
            } else {
    <?php
        $fields = array(
            'projectId' => $PROJECT_ID,
            'sessionId' => $sessionId,                      
            'promotionId' => $entry['couponId']
        );
    $downloadedCoupon = get_decoded_info( $SERVER_URL, $PORT, 'tos-member/user/membershipcoupon/download' , $fields );
    if($downloadedCoupon['message'] != ('Same CouponId downloaded before.' || 'Coupon is expired.' || 'Invalid Coupon.')){              
                    ?>
    window.location = "<?php echo $base_url; ?>coupon-singleview?id=<?php echo $entry["couponId"];?>";
    <?php           
    } else {
    if($downloadedCoupon['message'] == 'Same CouponId downloaded before.'){
    echo "alert('Coupon has already been downloaded');";    ?>
    <?php } else if ($downloadedCoupon['message'] == 'Coupon is expired.') {
    echo "alert('Coupon is expired');";
    } else {
    echo "alert('Invalid coupon.');";
            }
        }
    ?>
    }});
    <?php }?>
</script>

我尝试过以下方法通过javascript禁用该元素,但它没有工作

...
<?php } else if ($downloadedCoupon['message'] == 'Coupon is expired.') {?>
    document.getElementById('couponButton-<?php echo $entry['id']; ?>').disabled = true;
<?php } else {
...

使用JQuery,您可以更改禁用的属性。

$('#couponButton').prop("disabled", true);