<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <script type="text/javascript"> window.onload = function () { var date = new Date(); var month = date.getMonth()+1; if(month<10) month = "0"+month; var date_string = date.getFullYear()+"-"+month; var tr_nodes = document.getElementById("348794647969766383").rows; for(i=0; i<tr_nodes.length; i++) { td_nodes = tr_nodes[i].getElementsByTagName("td"); if(td_nodes[td_nodes.length-1].innerHTML == date_string) td_nodes[td_nodes.length-1].style.color = 'red'; } } </script> </head> <body> <table id="348794647969766383"> <tr class="even"> <td align="left" headers="YF">2012-06</td> </tr> <tr class="even"> <td align="left" headers="YF">2012-06</td> </tr> <tr class="even"> <td align="left" headers="YF">2012-06</td> </tr> <tr class="even"> <td align="left" headers="YF">2012-06</td> </tr> <tr class="even"> <td align="left" headers="YF">2012-05</td> </tr> </table> </body> </html>
firefox使用节点的childNodes属性时,获取的不准确,所以要使用的getElementsByTagName()方法获取子节点的集合