2010-03-23 71 views
1
<table> 
    <tr> 
     <td class = "nowrap cr" id="cr1">123123</td> 
     <td class = "nowrap ch" id="ch1">123123</td> 
    </tr> 
    <tr> 
     <td class = "nowrap cr" id="cr2">123123</td> 
     <td class = "nowrap ch" id="ch2">123123</td> 
    </tr> 
    <tr> 
     <td class = "nowrap cr" id="cr3">467574</td> 
     <td class = "nowrap ch" id="ch3">123123</td> 
    </tr> 
</table> 

我在哪里trchID == crID比较HTML表格单元格的内容在JavaScript

我已经写JS代码如下

$(function() { 
    for (var i = 0; i < 20; i++) 
    { 
     if ($('#cr' + i).val() == $('#ch' + i).val()) 
     { 
      $('#cr' + i).parent().css('font-weight', 'bold'); 
     } 
    } 
}); 

设置font-weight: bold如何,但它不工作。

让我知道我应该如何实现所需的输出?

回答

2

val()仅适用于输入元素。您需要使用

if($('#cr'+i).html() == $('#ch'+i).html()) 

,或者以文本值仅对比(这可能是你想要的)

if($('#cr'+i).text() == $('#ch'+i).text())