[英]Highlighting Table Rows does not work
我有一個HTML表格,如http://jsfiddle.net/Lijo/Hb28u/4/中給出的jquery腳本。 有四種用於突出顯示表行的jQuery方法。 最后兩種方法不起作用,它們為什么不起作用? 我正在用簡單的英語尋找解釋。
HTML
<table id="table1">
<tr> <td>N</td><td>Y</td></tr>
<tr class="y_n"><td>Q</td><td>N</td></tr>
</table>
<br/><br/>
<table id="table2">
<tr> <td>N</td><td>Y</td></tr>
<tr class="y_n"><td>Q</td><td>N</td></tr>
</table>
<br/><br/>
<table id="table3">
<tr> <td>N</td><td>Y</td></tr>
<tr class="y_n"><td>Q</td><td>N</td></tr>
</table>
<br/><br/>
<table id="table4">
<tr> <td>N</td><td>Y</td></tr>
<tr class="y_n"><td>Q</td><td>N</td></tr>
</table>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js">
腳本
$(document).ready(function()
{
//Apporach 1 - Highlight First Row
$('#table1 tr td:eq(0)').each(function() {
if ($(this).text() == 'N') {
$(this).parent().css('background-color', 'Orange');
}
});
//Apporach 2 - - Highlight Second Row
$('#table2 tr td:gt(0)').each(function() {
if ($(this).text() == 'N') {
$(this).parent().css('background-color', 'Orange');
}
});
//Apporach 3 - Highlight Second Row
$('#table3 tr td:eq(1)').each(function() {
if ($(this).text() == 'N') {
$(this).parent().css('background-color', 'Orange');
}
});
//Apporach 4 Highlight All Rows
$('#table4 tr td)').each(function() {
if ($(this).text() == 'N') {
$(this).parent().css('background-color', 'Orange');
}
});
});
現在它適用於jsfiddle
$('#table3 tr td:eq(3)').each(function() { // note that you search for td no. 3 and not 1
if ($(this).text() == 'N') {
$(this).parent().css('background-color', 'Orange');
}
});
//Apporach 4 Highlight All Rows
$('#table4 tr td').each(function() { // note that in your example you have a ) at the end of the selector
if ($(this).text() == 'N') {
$(this).parent().css('background-color', 'Orange');
}
});
//Apporach 3 - Highlight Second Row
$('#table3 tr:eq(1) td').each(function() { //second row
if ($(this).text() == 'N') {
$(this).parent().css('background-color', 'Orange');
}
});
//Apporach 4 Highlight All Rows
$('#table4 tr td').each(function() { //here you had a unnescessary ')'
if ($(this).text() == 'N') {
$(this).css('background-color', 'Orange');
}
});
希望你明白了:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.