展开全部
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table>
<tr>
<td>女</td>
<td>男</td>
</tr>
<tr>
<td>男</td>
<td>女</td>
</tr>
<tr>
<td>女</td>
<td>男</td>
</tr>
<tr>
<td>男</td>
<td>女</td>
</tr>
<tr>
<td>女</td>
<td>男</td>
</tr>
<tr>
<td>男</td>
<td>女</td>
</tr>
</table>
<script>
var tdArr = document.getElementsByTagName('td');
for(var i=0;i<tdArr.length;i++){
tdArr[i].innerText == "男" ?tdArr[i].style.backgroundColor ="yellow" : tdArr[i].style.backgroundColor = "red";
}
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询