2015-11-13 76 views
0

我在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> 
+0

也许是这样的:http://stackoverflow.com/a/5492951/636676 – Freddy

+0

您可以在你的问题你的'css'?谢谢。 – Rounin

+0

@Freddi我不认为这些涉及通过javascript创建表。 CSS不是问题。如果它不解析,CSS将无关紧要。 – Tony

回答

1

除非有别的东西不对劲,下面的样式规则:

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

应该很好地工作。

[加]

我现在明白了这个问题更好。

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

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

或者你可以(只是)在PHP中使用单引号和HTML双引号,像这样:

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

=====

例CSS & HTML在一起:

.hoverTable tr:hover { 
 
background-color: rgba(255, 255, 0, 1); 
 
}
<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>

+0

我在脚本中回显“

,但是我收到了这个Parse错误:语法错误,意外的T_STRING,期待','或';'在表中给出一个类的行上,代码运行良好,然后我尝试添加悬停在表格中,出于某种原因,javascript现在不喜欢这行代码,我的CSS和你的一样,除了颜色。 – Tony

+0

啊,我看到了什么问题,你需要在HTML中加入引号,所以解析器不会把它们误认为是PHP引号,或者你可以(简单地)在PHP中使用单引号,在HTML中使用双引号,像这样:'echo'

';' – Rounin

+0

我忘记了PHP不喜欢多个“”,现在清除了解析错误和表格渲染,但悬停仍然无法工作。这可能是因为我在iframe中显示了表格结果,但是我在脚本运行的页面上检查了两次,并且表格也不会在那里高亮显示。 – Tony

相关问题