我需要在onClick行后给出行颜色并请求其他页面并保持颜色更改 注意:当前更改行颜色并禁用在刷新页面后更改颜色
<script type="text/javascript">
var id = $row['id'];
function myPopup(id) {
if (id) {
location.href = "address.php?id="+id;
}
}
</script>
<script>
$(document).ready(function () {
$('#imagetable tr').click(function () {
$(this).css('background-color', 'Green');
});
});
</script>
<?php
$resualt=mssql_query("SELECT * FROM Address ") ;
echo "<table border='1' class='imagetable'
id='imagetable' width='50%'>\n";
echo '<tr>';
echo '<th>ID</th>'.'<th>User ID</th>'.'<th>Street</th>'.'<th>Quarter</th>'.'<th>Mobile Number</th>'.'<th>Email</th>'.'<th>From</th>'.'<th>To</th>'.'<th>Notes</th>';
echo '</tr>';
while ($row = mssql_fetch_assoc($resualt)) {
echo "<tr onClick='myPopup($row[id])'>\n"."<td >{$row['id']}</td>\n"."<td> {$row['user_id']}</td>\n"."<td>{$row['street']}</td>\n"."<td>{$row['quarter']}</td>\n"."<td>{$row['Phone_number']}</td>\n"."<td> {$row['email']}</td>\n"."<td>{$row['from_date']}</td>\n"."<td>{$row['to_date']}</td>\n"."<td>{$row['other_info']}</td>\n".'</tr>'."\n";
}
echo "</table>\n";
?>
任何帮助?
答案 0 :(得分:0)
在PHP中检查给定ID是否与while循环中的ID匹配。如果匹配,请根据您的具体情况添加样式参数或CSS类。
示例:
// Your code leading up to the while loop is here ...
while ($row = mssql_fetch_assoc($resualt)) {
echo "<tr onClick='myPopup($row[id])" . ($_GET['id'] == $row[id] ? "style='background-color: green'":"") . "'>\n".
"<td >{$row['id']}</td>\n".
// The rest of the code in your loop continues here ...
它不是最美丽或最安全的代码,但它适合您已经拥有的代码。