Cambiar fondo de etiqueta TD onmouseover onclik

L

LuisDavid

buenos dias grupo, tenia este problema, como puedo hacer para que
cambie el fondo de una celda, haciendo click, que cambie celda por
celda, no todas a la vez como se muestra:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
window.onload = function(){
docCells = document.getElementsByTagName("td");
for(i=0;i<docCells.length;i++){
docCells.onmouseover = new Function ("if
(this.style.backgroundColor == '')this.style.backgroundColor =
'blue'");
docCells.onmouseout = new Function ("if
(this.style.backgroundColor == 'blue')this.style.backgroundColor =
''");
docCells.onclick = new Function("if(this.style.backgroundColor ==
'blue')this.style.backgroundColor = 'red'");
}
}

</script>
<style type="text/css">
td{border:thin solid silver;}
</style>
</head>
<body>
<table>
<tr>
<td>Cell 1-1</td><td>Cell 1-2</td>
</tr>
<tr>
<td>Cell 2-1</td><td>Cell 2-2</td>
</tr>
</table>
</body>
</html>

la idea es que quede resaltado una celda, la que elija el usuario, y
no todas, como me queda, como puedo hacerlo, ayuda grupo; gracias de
antemano, por la ayuda que me puedan brindar.
 
E

Evertjan.

LuisDavid wrote on 12 jul 2009 in comp.lang.javascript:
buenos dias grupo, tenia este problema, como puedo hacer para que
cambie el fondo de una celda, haciendo click, que cambie celda por
celda, no todas a la vez como se muestra: [...]

la idea es que quede resaltado una celda, la que elija el usuario, y
no todas, como me queda, como puedo hacerlo, ayuda grupo; gracias de
antemano, por la ayuda que me puedan brindar.


Try this:

========================================
<script type='text/javascript'>

function OMover(){
if (this.style.backgroundColor == '')
this.style.backgroundColor = 'blue';
};

function OMout(){
if (this.style.backgroundColor == 'blue')
this.style.backgroundColor = '';
};

function Oclick(){
if (this.style.backgroundColor == 'blue')
this.style.backgroundColor = 'red';
else if (this.style.backgroundColor == 'red')
this.style.backgroundColor = 'blue';
};

function doOnload(){
docTable = document.getElementById('t');
docCells = docTable.getElementsByTagName('td');
for(var i=0;i<docCells.length;i++){
docCells.onmouseover = OMover;
docCells.onmouseout = OMout;
docCells.onclick = Oclick;
};
};

window.onload = doOnload;

</script>

<table id = 't'>
<tr>
<td>Cell 1-1</td><td>Cell 1-2</td>
</tr>
<tr>
<td>Cell 2-1</td><td>Cell 2-2</td>
</tr>
</table>

========================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top