I cannot disable link on non-zero date

2019-07-15 23:41发布

问题:

    <tr bgcolor="<?php echo $rowColor ?>"  >
        <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
        <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
        <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
        <td><font face="Arial, Helvetica, sans-serif"><?php echo $deliv_date; ?></font></td>
    </tr>
    <?php
        $i++;
        }
        mysql_close();

    ?>
    <tr bgcolor="<?php echo $rowColor ?>"  >
        <td>
            <strong>Total:</strong>
        </td>
        <td colspan="1">&nbsp;</td>
        <td ><font face="Arial, Helvetica, sans-serif"><?php echo $f8; ?></font></td>
        </td>
    </tr>
</table>
</div>
<div id="footer">
    <hr/>
    <div class="buttonwrapper">
        <a  class="boldbuttons" href="invoice_conf.php" <?php if ($deliv_date !=  '0000-00-00') echo 'disabled="disabled"' ?>><span>confirm delivery</span> </a>
    </div>

I am trying to disable the link in the last div when there is a non-zero delivery date. As you can see in the attached screen shot, I have a non-zero delivery date. When I try the link it is not disabled. Does anyone know why this could be,

Thanks

回答1:

Adding disabled attribute won't disable the link, if you want, just echo an # instead of the real source, or with Javascript, adding javascript: void(0)

Demo

<a class="boldbuttons" href="<?php echo ($deliv_date != '0000-00-00') ? 'invoice_conf.php' : 'javascript: void(0)'; ?>">
    <span>confirm delivery</span>
</a>

Or you can also use a class say disabled_link and if you want to prevent with pure CSS than use pointer-events: none;

Demo

Demo (Can also use lighter shades to indicate that the link is disabled)

.disabled_link {
    pointer-events: none;
    cursor: default;
}

Support for pointer-events is not impressive when it comes to Internet Explorer, I would suggest you to use span instead, like if the date is not 0000-00-00, then echo the text in span tags, else echo <a>



回答2:

add this after href.

onclick="return false;"

disabled is attribute for input tag.