在body標簽中使用了onmousedown用來監(jiān)聽鼠標事件,但是事件完全不生效。百度后都說是 <!DOCTYPE html>使event不生效。有說因為寬度問題,但是都試過還沒作用。如果去掉 <!DOCTYPE html>就可以生效使用代碼如下:<!DOCTYPE html><html> <head> <title>objecjs20.html</title> <script language="javascript" type="text/javascript"> <!-- function show_coords(e){ x=e.clientX; y=e.clientY; alert(e+"--X 坐標:"+x+",Y 坐標:"+y); } //--> </script> </head> <body onmousedown="show_coords(e)"> <div height="100%" width="100%">fdjl</div> </body></html>
<!DOCTYPE html>與onmousedown發(fā)生沖突是event不生效,為什么會這樣?
尚方寶劍之說
2019-03-15 14:15:13