這是我的循環代碼,用php創建表。我在每個中添加一個onclick函數。所以在點擊特定的單元格時,背景顏色會發生變化。我怎樣才能得到單元ID號碼顯示每次點擊。如何顯示正在選擇的html表格的單元格ID?
<html>
<head>
<script>
function changeColor(elem)
{
elem.style.background = "red";
}
</script>
</head>
<body>
<?php
$rows = 10; // define number of rows
$cols = 4;// define number of columns
echo "<table border='1'>";
for($tr=1;$tr<=$rows;$tr++){
echo "<tr>";
for($td=1;$td<=$cols;$td++){
echo "<td onclick=\"changeColor(this)\" > ".$tr." ".$td."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
有像許多圖書館jquery,ext2,原型,使這很容易。 –