日期:2014-05-16 浏览次数:20476 次
document.onmousedown=function(){ var x=event.clientX; var y=event.clientY; for(var k=0;k<6;k++){ for(var j=0;j<6;j++){ if(((x>100*j+14)&&(x<100*j+86))&&((y>100*k+14)&&(x<100*k+86))){ alert("范围内x:"+j+"\n"+"范围内y:"+k);break; } } } }
document.onmousedown=function(){ var x=event.clientX; var y=event.clientY; for(var j=0;j<6;j++){ if(x>100*0+14){if(x<100*0+86){alert("x:1");}}break; if(x>100*1+14){if(x<100*1+86){alert("x:2");}}break; if(x>100*2+14){if(x<100*2+86){alert("x:3");}}break; if(x>100*3+14){if(x<100*3+86){alert("x:4");}}break; if(x>100*4+14){if(x<100*4+86){alert("x:5");}}break; if(x>100*5+14){if(x<100*5+86){alert("x:6");}}break; } for(var k=0;k<6;k++){ if(y>100*0+14){if(y<100*0+86){alert("y:1");}}break; if(y>100*1+14){if(y<100*1+86){alert("y:2");}}break; if(y>100*2+14){if(y<100*2+86){alert("y:3");}}break; if(y>100*3+14){if(y<100*3+86){alert("y:4");}}break; if(y>100*4+14){if(y<100*4+86){alert("y:5");}}break; if(y>100*5+14){if(y<100*5+86){alert("y:6");}}break; }
<!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> <style type="text/css"> table { border:0; border-collapse:collapse; } td { border:1px solid #999; width:30px; height:30px; } </style> <script type="text/javascript"> window.onload = function() { var obj = document.getElementsByTagName('td'); for (var i = 0; i < obj.length; i ++) { obj[i].onclick = function() { this.style.backgroundColor = '#FF0'; alert('x:' + (this.parentNode.rowIndex + 1) + ', y:' + (this.cellIndex + 1)); } } } </script> </head> <body> <table> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td>