用JavaScript当用鼠标勾选一个CHECKBOX时,表格中对应的一行背景色变为黄色,文字字体变为红色粗体

来源:百度知道 编辑:UC知道 时间:2024/07/06 17:42:05
JavaScript 显示

<table border="1">
<tr><td><input type="checkbox"></td><td>1111111</td></tr>
<tr><td><input type="checkbox"></td><td>2222222</td></tr>
<tr><td><input type="checkbox"></td><td>3333333</td></tr>
<tr><td><input type="checkbox"></td><td>4444444</td></tr>
</table>
<script>
var chkBoxs = document.getElementsByTagName("input");
for(var i=0;i<chkBoxs.length;i++){
chkBoxs[i].onclick=function(){
tdText = this.parentNode.parentNode.childNodes[1];
if(this.checked){
tdText.style.fontWeight = "bold";
tdText.style.color = "red";
tdText.style.background = "yellow";
}else{
tdText.style.fontWeight = "normal";
td