簡體   English   中英

在動態添加的表行上添加onclick函數

[英]Adding onclick function on a dynamically added table row

我有一個頁面可以在表中顯示記錄,但是我可以做到這一點,但是在添加代碼后,突出顯示的表行將更改顏色,現在卻出現錯誤。

$result = mysqli_query($con,"SELECT * FROM mydb WHERE `Main Type`='main1' AND `DB Type`='Active' ORDER BY `Record ID`");

echo "<table border='1' style='width:100%; font-family:arial,Serif;font-style:regular;font-size:12px; color:black' CELLPADDING='1' CELLSPACING='0'>
<tr>
<th>Record ID</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>County</th>
<th>Price</th>
<th>Bed</th>
<th>Bath</th>
<th>Square Foot</th>
<th>Year Built</th>
<th>As Is Value</th>
<th>DB Type</th>
<th>Main Type</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr onclick='toggle(this)'>";
  echo "<td>" . $row['Record ID'] . "</td>";
  echo "<td>" . $row['Address'] . "</td>";
  echo "<td>" . $row['City'] . "</td>";
  echo "<td>" . $row['State'] . "</td>";
  echo "<td>" . $row['Zip Code'] . "</td>";
  echo "<td>" . $row['County'] . "</td>";
  echo "<td>" . $row['Price'] . "</td>";
  echo "<td>" . $row['Bed'] . "</td>";
  echo "<td>" . $row['Bath'] . "</td>";
  echo "<td>" . $row['Square Foot'] . "</td>";
  echo "<td>" . $row['Year Built'] . "</td>";
  echo "<td>" . $row['As Is Value'] . "</td>";
  echo "<td>" . $row['DB Type'] . "</td>";
  echo "<td>" . $row['Main Type'] . "</td>";
  echo "</tr>";
  }
echo "</table><br>";

echo "<script type='text/javascript'>";
echo "function toggle(it) { if ((it.style.backgroundColor == 'none') || (it.style.backgroundColor == '')){it.style.backgroundColor = 'yellow';}}";
echo "</script>"


mysqli_close($con);

基本上,我的主要目標是,如果用戶單擊某一行,則整行將更改顏色以表明它已被選中。 我的更高目標是移動鼠標而不是onclick。 我正在尋找最簡單,最簡單的方法來完成此任務,我覺得解決方案很簡單。 希望你們能幫上忙。

我得到的錯誤是

解析錯誤:語法錯誤,意外的T_STRING,期望為','或';' 在第59行的/home/u560877965/public_html/hud.php中

您在代碼中的字符串之后錯過了分號。

更改此:

echo "</script>"

對此:

echo "</script>";
//              ^ here (for those who can't see it)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM