<!DOCTYPE html> <html> <head> <title></title> </head> <body> <table width="500px" border="1px solid #ccc"> <thead> <td>首页</td> <td>数字</td> <td>关于</td> <td>我们</td> </thead> <tbody class="parent"> <!-- <tr> <td>1</td> <td class="small">2</td> <td>3</td> <td class="big" >5</td> </tr> --> </tbody> </table> <script type="text/javascript"> var parent=document.querySelectorAll(".parent")[0]; var tr=""; for(var i=0;i<9;i++){ tr+='<tr><td>1</td><td class="small">2</td><td>3</td><td class="big" >5</td></tr>' }; parent.innerHTML=tr; var small=document.querySelectorAll(".small"); var big=document.querySelectorAll(".big"); console.log(small); console.log(big); for(var j=0;j<small.length;j++){ if(big[j].innerHTML>small[j].innerHTML){ big[j].style.backgroundColor="red"; }else{ big[j].style.backgroundColor="white"; } } </script> </body> </html>