P
pamelafluente
Laurent Bugnion ha scritto:
I did this:
window.onload = addCellHandlers;
function addCellHandlers() {
var aDivs = document.getElementsByTagName("div");
var divElement;
for ( var i = 0; i < aDivs.length; i++ ) {
divElement = aDivs;
if ( divElement.getAttribute("hasHandlers") == "True" ) {
var myCell = this;
var evt = event;
divElement.onclick = function(evt) { cellClick( evt,
divElement ) };
divElement.onmouseover = function() { doOnmouseover(
divElement ) };
divElement.onmouseout = function() { doOnmouseout(
divElement ) };
}
}
}
This way the handlers do NOT get attached anymore to the DIVs. When the
mouse hover the cell nothing happen anymore (?).
Also why function(evt) has the argument and the following dont ? I am
not getting that.
-P
To solve this, you must not pass "this" to the function, but rather the
divElement itself:
if ( divElement.getAttribute("hasHandlers") == "True" )
{
divElement.onclick = function( evt ) { cellClick( evt, divElement ) };
divElement.onmouseover = function() { doOnmouseover( divElement ) };
divElement.onmouseout = function() { doOnmouseout( divElement ) };
}
I did this:
window.onload = addCellHandlers;
function addCellHandlers() {
var aDivs = document.getElementsByTagName("div");
var divElement;
for ( var i = 0; i < aDivs.length; i++ ) {
divElement = aDivs;
if ( divElement.getAttribute("hasHandlers") == "True" ) {
var myCell = this;
var evt = event;
divElement.onclick = function(evt) { cellClick( evt,
divElement ) };
divElement.onmouseover = function() { doOnmouseover(
divElement ) };
divElement.onmouseout = function() { doOnmouseout(
divElement ) };
}
}
}
This way the handlers do NOT get attached anymore to the DIVs. When the
mouse hover the cell nothing happen anymore (?).
Also why function(evt) has the argument and the following dont ? I am
not getting that.
-P