js 判断表格的值
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> </head> <body> <table width="500px" border="1px solid #ccc" id="table"> <thead> <tr id="thead"> <td id="sl">数量</td> <td >需求日期</td> <td class="small">标的价</td> <td class="company">中标</td> <td class="one"><input type="" name="" value="某公司"></td> <td class="two"><input type="" name="" value="工厂"></td> <td class=three><input type="" name="" value="年有限"></td> <td class="two"><input type="" name="" value="黄老吉"></td> <td class=three><input type="" name="" value="年有限"></td> </tr> </thead> <tbody class="parent"> <tr> <td><input type="" name="" value="1"></td> <td><input type="" name="" value="1"></td> <td class="small"><input type="" name="" value="500"></td> <td class="company"><input type="" name="" value="某公司"></td> <td class='one'><input type="" name="" value="1200"></td> <td><input type="" name="" value="100"></td> <td><input type="" name="" value="800"></td> <td><input type="" name="" value="100"></td> <td><input type="" name="" value="800"></td> </tr> <tr> <td><input type="" name="" value="1"></td> <td><input type="" name="" value="1"></td> <td class="small"><input type="" name="" value="600"></td> <td class="company"><input type="" name="" value="工厂"></td> <td class='one'><input type="" name="" value="300"></td> <td><input type="" name="" value="800"></td> <td><input type="" name="" value="200"></td> <td><input type="" name="" value="800"></td> <td><input type="" name="" value="200"></td> </tr> <tr> <td><input type="" name="" value="1"></td> <td><input type="" name="" value="1"></td> <td class="small"><input type="" name="" value="700"></td> <td class="company"><input type="" name="" value="年有限"></td> <td class='one'><input type="" name="" value="500"></td> <td><input type="" name="" value="150"></td> <td><input type="" name="" value="8210"></td> <td><input type="" name="" value="150"></td> <td><input type="" name="" value="1000"></td> </tr> <tr> <td><input type="" name="" value="1"></td> <td><input type="" name="" value="1"></td> <td class="small"><input type="" name="" value="500"></td> <td class="company"><input type="" name="" value="黄老吉"></td> <td class='one'><input type="" name="" value="500"></td> <td><input type="" name="" value="150"></td> <td><input type="" name="" value="1000"></td> <td><input type="" name="" value="150"></td> <td><input type="" name="" value="1000"></td> </tr> </tbody> </table> <script type="text/javascript"> function panduan(table) { var tableObj = document.getElementById('table'); for (var i = 1; i < tableObj.rows.length; i++) { //遍历Table的所有Row for (var j = 0; j < tableObj.rows[i].cells.length; j++) { //遍历Row中的每一列 if(tableObj.rows[i].cells[3].firstChild.value==tableObj.rows[0].cells[j].firstChild.value){ var number1=Number(tableObj.rows[i].cells[j].firstChild.value); var number2=Number(tableObj.rows[i].cells[2].firstChild.value); if(number1>number2){ tableObj.rows[i].cells[j].firstChild.style.border="3px solid red"; }else{ tableObj.rows[i].cells[j].firstChild.style.border="3px solid green"; } break; } } } } panduan(table); </script> </body> </html>