<table id="aaa" >
<tr >
<td ><input type="checkBox" id="a1"> </td>
<td width="130" > <input type="checkBox"> </td>
<td width="180" ><input type="checkBox"> </td>
<td align="left" > <span>44444444 </span></td>
</tr>
<tr >
<td ><input type="checkBox" id="a2"> </td>
<td width="130" > <input type="checkBox"> </td>
<td width="180" ><input type="checkBox"> </td>
<td align="left" > <span>5555 </span></td>
</tr>
</table>
<script language=javascript>//var aa=document.getElementById("aaa")
//var i=0; //0 cell
////alert(aa.rows.length)
//for(var m=0;m<aa.rows.length;m++){
// if(aa.rows[m].cells[i].childNodes[0].type=="checkbox"){
// alert(aa.rows[m].cells[i].innerHTML)
// alert(aa.rows[m].cells[i].childNodes[0].type)
// }
//}
function changeColor(){
// var arr=document.getElementById("state"); //state是td的ID //document.getElementById("")取到的不是数组
var arr=document.getElementById("aaa").childNodes[0].childNodes[0].childNodes[3];
if(arr.innerText="44444444"){
arr.style.cssText="font-weight:bold;color:red;";
}
else if(arr.innerText="可供"){
arr.style.cssText="font-weight:bold;color:blue;";
}
}
changeColor();
</script>
<tr >
<td ><input type="checkBox" id="a1"> </td>
<td width="130" > <input type="checkBox"> </td>
<td width="180" ><input type="checkBox"> </td>
<td align="left" > <span>44444444 </span></td>
</tr>
<tr >
<td ><input type="checkBox" id="a2"> </td>
<td width="130" > <input type="checkBox"> </td>
<td width="180" ><input type="checkBox"> </td>
<td align="left" > <span>5555 </span></td>
</tr>
</table>
<script language=javascript>//var aa=document.getElementById("aaa")
//var i=0; //0 cell
////alert(aa.rows.length)
//for(var m=0;m<aa.rows.length;m++){
// if(aa.rows[m].cells[i].childNodes[0].type=="checkbox"){
// alert(aa.rows[m].cells[i].innerHTML)
// alert(aa.rows[m].cells[i].childNodes[0].type)
// }
//}
function changeColor(){
// var arr=document.getElementById("state"); //state是td的ID //document.getElementById("")取到的不是数组
var arr=document.getElementById("aaa").childNodes[0].childNodes[0].childNodes[3];
if(arr.innerText="44444444"){
arr.style.cssText="font-weight:bold;color:red;";
}
else if(arr.innerText="可供"){
arr.style.cssText="font-weight:bold;color:blue;";
}
}
changeColor();
</script>
解决方案 »
- jq 改变文本框背景颜色
- 什么网站第一次打开,JS写的图片特效显示的位置会错位,刷新一下又好了
- js里的日期计算
- |zyciis| 为什么我的按tab 转到其他控件focus()的代码无效 哪里出错了?
- 关于window.open的刷新问题
- 谁知道哪有使用jquery ui技术做成的网站范例?
- 求在ASP中实现类似于Word,Excel中分页符功能的方法或组件
- 怎么实现:在文本框中只能出现小于36的数字和顿号?100分在线等
- JAVASCRIPT 取得控件数组的大小
- 怎样在javascript中取得session中对象的值?
- 奇怪的JS文件
- 如何利用DIV 和 jscript 实现页面分帧效果
<head>
<script language=javascript>
function setcolor(obj){
switch(obj.innerText){
case "red":
obj.style.cssText="font-weight:bold;color:red;";
break;
case "blue":
obj.style.cssText="font-weight:bold;color:blue;";
break;
case "black":
obj.style.cssText="font-weight:bold;color:black;";
break;
}}
</script> </head>
<form>
<body><table id="tab1" >
<tr>
<td onclick="setcolor(this)">red</td>
<td onclick="setcolor(this)">blue</td>
<td onclick="setcolor(this)">black</td>
</tr>
</table>
</body>
</form>
</html>
如果所有的td都要判断用上面的
注意,下面的td的id和name属性都要有,因为在FF浏览器里使用DOM2标准,使用name属性,而IE里用id <table id="tab" border=1>
<tr>
<td>占用</td><td id="state" name="state">可供</td>
<tr>
<tr>
<td>可供</td><td id="state" name="state">占用</td>
<tr>
<tr>
<td>占用</td><td id="state" name="state">可供</td>
<tr>
<tr>
<td>可供</td><td id="state" name="state">占用</td>
<tr>
</table>
<input type="button" value="change" onclick="changeColor();">
<script>
//自定义去空格方法
String.prototype.trim=function(){
return this.replace(/^\s*/g,"").replace(/\s*$/g,"");
}
function changeColor(){
//var arr=document.getElementById("tab").getElementsByTagName("td");//tab是table的ID
var arr=document.getElementsByName("state");//state是td的name属性
for(var i=0;i<arr.length;i++){
if(arr[i].firstChild.data.trim()=="占用"){
arr[i].style.cssText="font-weight:bold;color:red;";
}else if(arr[i].firstChild.data.trim()=="可供"){
arr[i].style.cssText="font-weight:bold;color:blue;";
}
}
}
</script>