我需要在点击行后给行颜色,并请求其他页面并保持颜色更改注意:当前更改行颜色并禁用在重新构建页面后更改的颜色
<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";
?>
有什么帮助吗?
在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 ...
这不是最漂亮或最安全的代码,但我认为它适合你已经拥有的代码。