简体   繁体   中英

How to disable a href

How to disable a href link if there's value in PR row from database? Like my sample table below, if there PR disable the link.

Table

item_name | PR     |  < Add >  |

ballpen   | pr100  |    <a>    |
pencil    |        |    <a>    |
Paper     |        |    <a>    |
Clip      |        |    <a>    |

Codes,

  <?php
    echo '<table>
        <thead>
        <tr>
        <th></th>
        <th>Item Name</th>
        <th>PR</th>
        <th><Add></th>
        </tr>
        </thead>';
    echo '<tbody>';
    $i = 1;
    while ($row = $result1->fetch_assoc()) {
        if ($row['app_cn'] != '') {
            echo '<tr>
            <td>' . $i++ . '</td>
            <td>' . $row['item_name'] . '</td>
            <td>' . $row['pr'] . '</td>
            <td align="center"><a class="fancybox" href="addpr.php?counts=' . $row["id"] . '"></a></td>
       </tr>';
        }
?>

I want to disable ballpen row <a class="fancybox" href="addpr.php?counts=' . $row["id"] . '"></a> if there's PR in row

while ($row = $result1->fetch_assoc()) {
    if ($row['app_cn'] != '') {
        echo '<tr>
        <td>' . $i++ . '</td>
        <td>' . $row['item_name'] . '</td>
        <td>' . $row['pr'] . '</td>

        <td align="center">';
if (!empty($row['pr'])){
    echo '<a class="fancybox" href="addpr.php?counts=' . $row["id"] . '"></a>';
}
echo'</td></tr>';
}

href属性设置为"javascript:;"

You can use the following:

...
echo '<td align="center"><a class="fancybox" href="'.(($row['pr']!="")?'addpr.php?counts='.$row["id"]:'#'). '"></a></td>';

if you are trying to remove the modal (fancybox) functionality then you can do so by removing the class of the link with jquery or javascript..

example

$('a[href="PR100"]').removeClass('fancybox');

this checks each link on the page. if the link has an href attribute that is equal to PR100, we remove the fancybox class which would prevent the popup.

your question is pretty cryptic though. I'm guessing this is what youre asking..

 <?php
    echo '<table>
        <thead>
        <tr>
        <th></th>
        <th>Item Name</th>
        <th>PR</th>
        <th><Add></th>
        </tr>
        </thead>';
    echo '<tbody>';
    $i = 1;
    while ($row = $result1->fetch_assoc()) {
        if ($row['app_cn'] != '') {
            $url = $row['pr'] ? 'addpr.php?counts=' . $row['pr'] : '#';
            echo '<tr>
            <td>' . $i++ . '</td>
            <td>' . $row['item_name'] . '</td>
            <td>' . $row['pr'] . '</td>
            <td align="center"><a class="fancybox" href="{$url}"></a></td>
       </tr>';
        }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM