利用getElementById得到td的值, 注意一定要加innerText,因为document.getElementById("a").得到的只是一个对象
代码如下
<script language="javascript">
function cc()
{
i f(document.getElementById("a").innerText=="111" )
{
document.getElementById.("a")style.background="#ff0000"
}
else{
document.getElementById("a").style.background="#000000"
}
}
</script>
<body onload="cc()">
<table>
<tr>
<td id="a">111</td>
<td id="b">222</td>
</tr>
</table>
</body>
注:
innerTEXT
是表示html的标签中的文本
例如:
<p name="ppp"><p>
<script>
ppp.innerTEXT="HELLO"
</script>
相当如<p name="ppp">HELLO<p>