我由于某种原因试图使用jquery获取表,但无法获取特定行
我可以帮忙
jQuery的
$('table').on('click','tr:gt(0)',function(e){
row=$(this).closest("tr");
$('tr').css('background-color', '');
row.css('background-color', 'yellow');
});
的HTML
<table id="receivedFeeds" border="1">
<tr>
<th>Feed Address</th>
<th>Feed name</th>
<th>Received from</th>
</tr>
</table>
的PHP
function addSendedFeedToUser(){// create a table of links and the user who send them
connectToDB();
$username=mysql_real_escape_string($_SESSION['username']);
$sql=mysql_query("SELECT * FROM send_feed WHERE user_receive='$username'") or die(mysql_error());
while($row=mysql_fetch_array($sql)){
echo '<tr> <td>'.$row['feed_url'].'</td><td>'.$row['feed_name'].'</td> <td>'.$row['user_send'].'</td></tr>';
}
}
$(this)
足够使用.closest()
它,因为选择器本身是一行。
$('table').on('click','tr:gt(0)',function(e){
row = $(this);
$('tr').css('background-color', 'none');
row.css('background-color', 'yellow');
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句