有关JS显示本列相同字符的问题
菜鸟跪求指点,谢谢
1、有三列数字如:
6 7 4
8 1 2
5 4 5
4 5 7
5 7 7
2 1 2
4 7 5
5 2 7
2、当鼠标光标经过或者点击某一个
数字的时候,该数字和它上面的数
字如果在该列出来过,则把这两个数
字标示出来。如:
6 7 4
8 1 2
5 4 5
4 5 7
5 7 7
2 1 2
4 7 5
5 2 7
求高人指点,谢谢
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function init(){
var table=document.getElementById("test");
var tds=table.getElementsByTagName("td");
for(var i=0;i<tds.length;i++){
tds[i].setAttribute("num",i);
tds[i].onclick=change;
}
}
function change(){
var table=document.getElementById("test");
var num=this.getAttribute("num");
var tds=table.getElementsByTagName("td");
for(var i=num-3;i>=0;i-=3){
if(tds[i].innerHTML==this.innerHTML){
tds[i].innerHTML="<font color=red>"+tds[i].innerHTML+"</font>"
}
}
this.innerHTML="<font color=red>"+this.innerHTML+"</font>";
}
window.onload=init;
</script>
</head>
<body>
<table id="test">
<tr>
<td>6</td>
<td>7</td>
<td>4</td>
</tr>
<tr>
<td>8</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>5</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>7</td>
</tr>
<tr>
<td>5</td>
<td>7</td>
<td>7</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>4</td>
<td>7</td>
<td>5</td>
</tr>
<tr>
<td>5</td>
<td>2</td>
<td>7</td>
</tr>
</table>
</body>
</html>
这样试试