addEventListener在Firefox和Opera中无法识别
我的代码如下:
var gidfront;
for(k = 0; k < rows; k++)
{
var frontTR = document.createElement( "tr ");
frontTable.appendChild(frontTR);
for(g = 0; g < cols; g++)
{
gidfront= grid[k][g].substr(4);
var frontTD = document.createElement( "td ");
frontTR.appendChild(frontTD);
if(gidfront != "0000 ")
{
var frontDIV = document.createElement( "div ");
var divid = "f " + grid[k][g];
frontDIV.id = divid
frontDIV.className = "cell ";
if (navigator.appName != "Microsoft Internet Explorer ")
{
frontDIV.addEventListener( "click ", doclick(grid[k][g]), false);
}
else
{
frontDIV.onclick = "javascript:doclick( ' " + grid[k][g] + " ') ";
}
frontTD.appendChild(frontDIV);
}
}
}
function doclick(id)
{
alert(id);
}
------解决方案--------------------if(document.addEventListener){
//使用addEventListener
}else{
//使用attachEvent
}
------解决方案--------------------我用过也不行,后来直接这样写省事多了
document.onmousemove = mm;
document.onmouseup = mu;
function mm(e){}
function mu(e){}
------解决方案--------------------不知道楼主怎么使用的,ff中绝对可以用addEventListener的。