Make table row TR a link

I have a table written in PHP using the echo command because it makes a calendar. I want every line in the calendar to become a link (to select every week). I know I can use JavaScript, but for some reason it does not work when it is in the echo command. Is there any other way to do this?

BTW: I do not want the text to become links only for all cells in a row to become links.

PLEASE let me know if this is possible or what alternatives.

here is my code that i still have.

<style style="text/css">
    .hoverTable{
        width:100%; 
        border-collapse:collapse; 
    }
    .hoverTable td{ 
        padding:7px; border:#4e95f4 1px solid;
    }
    /* Define the default color for all the table rows */
    .hoverTable tr{
        background: #b8d1f3;
    }
    /* Define the hover highlight color for the table row */
    .hoverTable tr:hover {
          background-color: #ffff99;
    }
h3 {
    color: #FFF;
}
</style>

.

<table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="8" align="center" bgcolor="#666666"><h3>January</h3></td>
      </tr>
      <tr>
        <td width="30" align="center" bgcolor="#0099FF">W</td>
        <td width="30" align="center" bgcolor="#0099FF">S</td>
        <td width="30" align="center" bgcolor="#0099FF">M</td>
        <td width="30" align="center" bgcolor="#0099FF">T</td>
        <td width="30" align="center" bgcolor="#0099FF">W</td>
        <td width="30" align="center" bgcolor="#0099FF">T</td>
        <td width="30" align="center" bgcolor="#0099FF">F</td>
        <td width="30" align="center" bgcolor="#0099FF">S</td>
      </tr>

      <?php 
                    $timestamp = mktime(0,0,0,1,1,$year);
                    $maxday = date("t",$timestamp);
                    $thismonth = getdate ($timestamp);
                    $startday = $thismonth['wday'];
                    $week =  date("W", $timestamp);

            echo "<table class='hoverTable'>";
            for ($i=0; $i<($maxday+$startday); $i++) {

                $date  = mktime(0, 0, 0, 1, $i - $startday + 1, $year);

                            //want to make this row below a link

                if(($i % 7) == 0 ) echo "<tr><td width='30'>" . date('W', $date) . "</a></td>";

                if($i < $startday) echo "<td></td>";
                 else echo "<td align='center' valign='middle' height='20px' width='30px'>". ($i - $startday + 1) . "</td>";

                if(($i % 7) == 6 ) echo "</tr>";
}
            echo "</table>";

?>
+4
source share
4 answers

, . , jquery javascript

<table>
    <tr>
        <td onclick="window.location = 'index.html';">Click me!</td>
    </tr>
</table>

..

<table>
    <tr>
        <td style="cursor:pointer" 
            onMouseover="window.status='http://www.stackoverflow.com/'" 
            onMouseout="window.status=''" 
            onMouseup="window.location='http://www.stackoverflow.com/'">
                Click me!
        </td>
    </tr>
</table>

$("tr").click(function(){
});

$('tr').bind('click', function(){
    window.location = 'http://stackoverflow.com';
});
0

, , , , . ?

  • td, .
  • td
  • text-decoration: none,

:

<td>
    <a  href="http://www.joshuakissoon.com" title="Joshua Kissoon." style="line-height: 100%; text-decoration: none; width:100%; height:100%">Checkout Joshua Kissoon.</a>
</td>

JSFiddle: http://jsfiddle.net/KrRzP/5/

+1

a, td.

a {
  display: block;
  height: 100%;
  width: 100%;
}

td {
  padding: 0;
}

: http://jsfiddle.net/a2w5w/

+1

You can use jquery

$(document).ready(function(){
    $(".calander tr").click(function() {
        $(".calander tr").removeClass("redColor");
        $(this).addClass("redColor");
    });
});

JSFiddle: http://jsfiddle.net/M94HE/

Update:

If I realized that your question is the following - your answer

http://jsfiddle.net/Z3sjL/

+1
source

Source: https://habr.com/ru/post/1530798/


All Articles