在鼠标悬停时突出显示表格行

时间:2015-11-13 17:36:44

标签: javascript css

我在javascript调用中创建一个表,并通过选择链接的页面上的iframe显示数据。当用户将鼠标悬停在一行上时,我试图突出显示一个表格行。我在表中添加了一个类,然后是后续的css代码,但是我在表格出现的行上得到了一个解析错误。关于如何清除它的任何想法?

<!DOCTYPE HTML>
<html lang = "en">
  <head>
    <link rel="stylesheet" type="text/css" href="mystylesheet.css">
    <title>Tech Order Department.html</title>
    <meta charset = "UTF-8" />


</head>

<body>


    <h2>Completed Projects</h2>
<br>

<?php
$servername = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 

//Set up and run my Query

$sql = "SELECT Project, Client, DateReceived, LastName, FinalReviewDate, DateDelivered, DateAccepted FROM Projects
              WHERE DateAccepted IS NOT NULL
              ORDER BY DateAccepted DESC";
$result = $conn->query($sql);

//Display results

if ($result->num_rows > 0) {
     echo "<table class="hoverTable"><tr><th>Client</th><th>Project</th><th>Point of Contact</th><th>Date Project Received</th><th>Final Review Date</th><th>Date Delivered</th><th>Date Accepted</th></tr>";
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<tr><td>" . $row["Client"]. "</td><td>" . $row["Project"]. "</td><td> " . $row["LastName"]. "</td><td> " . $row["DateReceived"]. "</td><td> " . $row["FinalReviewDate"]. "</td><td> " . $row["DateDelivered"]. "</td><td> " . $row["DateAccepted"]. "</td></tr>";
     }
     echo "</table>";
} else {
     echo "0 results";
}

$conn->close();
?> 

  </body>
</html>

1 个答案:

答案 0 :(得分:1)

除非出现其他问题,否则以下样式规则:

.hoverTable tr:hover {
background-color: rgba(255, 255, 0, 1);
}

应该完美无缺。

<强> [ADDED]

我现在更了解这个问题。

您需要转义HTML中的引号,因此解析器不会将它们误认为是PHP引号。试试这个:

echo "<table class=\"hoverTable\">";

你可以(简单地)使用PHP中的单引号和HTML中的双引号,如下所示:

echo '<table class="hoverTable">';

=====

CSS&amp; HTML在一起:

&#13;
&#13;
.hoverTable tr:hover {
background-color: rgba(255, 255, 0, 1);
}
&#13;
<table class="hoverTable">
  
<tr>
<th>Client</th>
<th>Project</th>
<th>Point of Contact</th>
<th>Date Project Received</th>
<th>Final Review Date</th>
<th>Date Delivered</th>
<th>Date Accepted</th>
</tr>

<tr>
<td>Client1</td>
<td>Project1</td>
<td>LastName1</td>
<td>DateReceived1</td>
<td>FinalReviewDate1</td>
<td>DateDelivered1</td>
<td>DateAccepted1</td>
</tr>
  
<tr>
<td>Client2</td>
<td>Project2</td>
<td>LastName2</td>
<td>DateReceived2</td>
<td>FinalReviewDate2</td>
<td>DateDelivered2</td>
<td>DateAccepted2</td>
</tr>
  
<tr>
<td>Client3</td>
<td>Project3</td>
<td>LastName3</td>
<td>DateReceived3</td>
<td>FinalReviewDate3</td>
<td>DateDelivered3</td>
<td>DateAccepted3</td>
</tr>
  
<tr>
<td>Client4</td>
<td>Project4</td>
<td>LastName4</td>
<td>DateReceived4</td>
<td>FinalReviewDate4</td>
<td>DateDelivered4</td>
<td>DateAccepted4</td>
</tr>
  
<tr>
<td>Client5</td>
<td>Project5</td>
<td>LastName5</td>
<td>DateReceived5</td>
<td>FinalReviewDate5</td>
<td>DateDelivered5</td>
<td>DateAccepted5</td>
</tr>
  
</table>
&#13;
&#13;
&#13;