[英]how can I make each <tr> clickable in php?
我在 php 中使用 laravel 刀片有以下代碼,它允許我將當月的所有日期作為表格獲取,我想讓每個“”都可以通過 php 進行點擊,我不確定這是否可能。
<table class="table-bordered">
<tbody>
@php
$date = date('F Y');//Current Month Year
$row_count=0;
$col_count=0;
while (strtotime($date) <= strtotime(date('Y-m') . '-' . date('t', strtotime($date)))) {
if($row_count%4==0){
echo "<tr>";
$col_count=1;
}
$day_num = date('j', strtotime($date));
$month_num = date('m', strtotime($date));
$day_name = date('l', strtotime($date));
$day_abrev = date('S', strtotime($date));
$day = "$day_name $day_num";
$date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
echo '<td>' . $day . '</td>';
if($col_count==4){
echo "</tr>";
}
$row_count++;
$col_count++;
}
@endphp
</tbody>
</table>
如果你想讓<tr>
可點擊,只需echo "<tr onclick='your_js_function_name_or_code'>";
.
例如,如果你想要警報,只需echo "<tr onclick='alert(1)'>";
.
您可以使用onclick()
調用 function
function showValue(value){ alert(value) }
table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%; } td, th { border: 1px solid #dddddd; text-align: left; padding: 8px; } tr:nth-child(even) { background-color: #dddddd; }
<table> <tr onclick="showValue(1)"> <th>Company</th> <th>Contact</th> <th>Country</th> </tr> <tr onclick="showValue(1)"> <td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Germany</td> </tr> </table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.