oStart.onclick=function()
{
clearTimeout(timer);
timer=setTimeout(function game(){
oCont.innerHTML='*Math.random())] +')
';
var ap=oCont.getElementsByTagName('p')[0];
ap.style.left=Math.round(800*Math.random())+'px';
doMove(ap,'top',1,480,function(){
shake(op,'top',function(){
timer=setTimeout(game,100)
});
});
ap.onclick=function()//为何这里无法触发ap的点击事件?
{
alert(1)
}
},100)
}
请问大神们,为何ap的点击事件无法触发,很困惑,求解答,谢谢!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
作用域的问题。
你的ap是在setTimeout里定义的,在外面ap是undefined,当然绑定不上事件了。