日期:2014-05-16  浏览次数:20465 次

请问如何取得Div下的 Table 对象(Table没有ID)
<div class= 'view view-case-view-all ' > 
  <div class= 'view-content view-content-case-view-all ' > 
  <table border="1" > 
  <tr class="odd" > 
  <td class="view-field view-field-node-title" >任务测试1 </td > 
<td class="view-field view-field-workflow-states-state" >执行中 </td > 
  </tr > 
  <tr class="even" > 
  <td class="view-field view-field-node-title" >任务测试2 </td > 
<td class="view-field view-field-workflow-states-state" >完成 </td > 
  </tr > 
  <tr class="even" > 
  <td class="view-field view-field-node-title" >任务测试3 </td > 
<td class="view-field view-field-workflow-states-state" >执行中 </td > 
  </tr > 
  </table > 
  </div > 
</div > 

请问如何根据 table 中每行 第二个TD中的内容控制表格行的颜色? 
主要的困难是Table 没有ID.不知如何取得Table 对象 

拜谢各位了.

补充一下,就是想让表格中的每行根据"完成"/"执行中"这两种不同的状态改变颜色. 

再次拜谢

------解决方案--------------------
div id 知道吗?如果最外层的div id知道就好办了,
使用
var tbl = document.getElementById("outtest div ID").childNodes[0].childNodes[0];
可以取得table对象
改变table行的颜色,通过改变i行的样式实现的代码是
tbl.rows[i].className = "行的className";
------解决方案--------------------
HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>

<div class='view view-case-view-all'>
<div class='view-content view-content-case-view-all'>
<table border="1">
<tr class="odd">
<td class="view-field view-field-node-title">任务测试1</td>
<td class="view-field view-field-workflow-states-state">执行中</td>
</tr>
<tr class="even">
<td class="view-field view-field-node-title">任务测试2</td>
<td class="view-field view-field-workflow-states-state">完成</td>
</tr>
<tr class="even">
<td class="view-field view-field-node-title">任务测试3</td>
<td class="view-field view-field-workflow-states-state">执行中</td>
</tr>
</table>
</div>
</div>

<script language='javascript'>
function setClor()
{
    var tdArray = document.getElementsByTagName("td");

    for(var i=0;i<tdArray.length;i++)
    {
        with(tdArray[i]){
            if(innerText == "完成"){
                parentNode.bgColor = "red"; 
            }
        }
    }
}
setClor();
</script>
</BODY>
</HTML>