我试图将类添加到一行$('tr:first-child').next().addClass("current");
整个 html
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>All Rows</title>
<script type="text/javascript" src="jquery.js"></script>
<style type="text/css">
.container {padding-left: 20px; padding-right: 20px;}
.forms{
display:inline-block;
margin-top:2%;
}
.buttons{border:1px solid #708090;}
input {margin-bottom:2%;margin-right:5%;}
button{margin-right:3%;}
.forms{border-top:3px solid #708090;}
.tableholder{height:300px; overflow-y:auto;}
.current{background-color:pink;}
</style>
<script type="text/javascript">
$(document).ready(function(){
$.get("getall.php", function(data){
{
$('.tableholder').append(data);
}
});
$('tr:first-child').next().addClass("current");
$("#next").click(function(){
$("table").find('.current').removeClass("current");
});
});
</script>
</head>
<body>
<div id="sc" class="container">
<div class="tableholder">
</div>
</div>
</body></html>
和我的 php 脚本。不要担心已弃用的 mysql 函数。我们使用旧的 php 安装
<?php
$host = "localhost";
$user = "root";
$pass = "";
$databaseName = "caliban";
$tableName = "caliban";
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
$result = mysql_query("SELECT * FROM $tableName");
$array = mysql_fetch_assoc($result);
$result = mysql_query("SELECT * FROM $tableName");
$rows = Array();
$i=0;
while($row = mysql_fetch_assoc($result)){
//array_push($rows, $row);
$rows[$i++] = $row;
}
echo "<table id='tab' border='1'>
<thead>
<tr>
<th><form><input type='checkbox' /></form></th>
<th>firstname</th>
<th>lastname</th>
<th>city</th>
<th>continent</th>
</tr>
</thead>
<tbody>";
for($j=0;$j<count($rows); $j++){
$id = $rows[$j]['id'];
$firstname = $rows[$j]['firstname'];
$lastname = $rows[$j]['lastname'];
$city = $rows[$j]['city'];
$continent = $rows[$j]['continent'];
echo
"<tr id='$id' class=''>
<td><input type='checkbox' /></td>
<td>$firstname</td>
<td>$lastname</td>
<td>$city</td>
<td>$continent</td>
</tr>";
}
echo "</tbody>
</table>";
?>
获取成功,表格按原样显示,但无法应用课程。我哪里出错了?