dongxiee0744 2014-03-09 05:11
浏览 162
已采纳

使表行TR成为链接

I have a table made in PHP with the echo command because it's to make a calendar. I want each row in the calendar to become a link (to select each week). I know I can use JavaScript but it wont work when it's in an echo command for some reason. Is there another way to do this?

BTW: I don't want the text to become links just all the cells in the row to become links.

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

here is my code I have so far.

<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条回答 默认 最新

  • dtwzwmv87399 2014-03-09 06:15
    关注

    You can just wrap your cell in an anchor if you make the anchor a block level element. Or you can use event attributes, jquery, or javascript

    html event attributes

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

    a little more..

    <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>
    

    jquery

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

    javascript

    $('tr').bind('click', function(){
        window.location = 'http://stackoverflow.com';
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊