<!DOCTYPE html>
<HTML>
<HEAD>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
video {
right: 0;
bottom: 0;
min-width: 50%;
min-height: 50%;
max-width: 90%;
max-height:90%;
width: auto;
height: auto;
</style>
</HEAD>
<BODY bgcolor=black>
<center><video width="853" height="480" autoplay="autoplay">
<source src="file:///C:/Program Files/NARUTO SHIPPUDEN Ultimate Ninja STORM 2/IntroMovie.mp4" type="video/mp4" />
Your browser does not support HTML5 video.
</video></center>
</BODY>
<script type="text/javascript">
document.body.addEventListener("onclick", function(){
alert("Hello! I am an alert box!!");
});
document.body.addEventListener("oncontextmenu", function(){
alert("Hello! I am an alert box!!");
});
document.body.addEventListener("onkeypress", function(){
alert("Hello! I am an alert box!!");
});
</script>
</HTML>
出于某种原因,每当我点击身体时(无论是在视频内部还是外部),警报框都不会弹出。
有没有理由说明代码没有显示警告框?
答案 0 :(得分:2)
应该是:
document.body.addEventListener("click", function(){
alert("Hello! I am an alert box!!");
});
您在每个操作前面添加了一个不必要的“on”(这对于attachEvent是必需的,但不是addEventListener)。
应该是: