我无法在底部使用此点击事件监听器来处理我的外部文件。它在我调用HTML时工作,但不在文件中。第一个函数的EventListener也可以正常工作。这是我的代码。
function returnScore(){
alert("Your Score is "+ getScore()+"/100");
}
submit.addEventListener("click",returnScore);
var slideIndex = 1;
showSlides(slideIndex);
var next=document.getElementById("next");
function plusSlides() {
showSlides(slideIndex ++);
}
next.addEventListener("click",plusSlides);
Blockquote这里有一些HTML,我在底部包含了脚本
<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<fieldset><legend><h3>True or False, The American and National League both
have a DH?</h3></legend>
<label class="container">True<br>
<input type="radio" name="question8" value="A">
<span class="checkmark"></span>
</label>
<label class="container">False<br>
<input type="radio" name="question8" value="B">
<span class="checkmark"></span>
</label>
</fieldset>
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<fieldset><legend><h3>Who owns the record for most stolen bases in a season?
</h3></legend>
<label class="container">Tim Raines<br>
<input type="radio" name="question9" value="A">
<span class="checkmark"></span>
</label>
<label class="container">Rickey Henderson<br>
<input type="radio" name="question9" value="B">
<span class="checkmark"></span>
</label>
<label class="container">Lou Brock<br>
<input type="radio" name="question9" value="C">
<span class="checkmark"></span>
</label>
<label class="container">Ty Cobb<br>
<input type="radio" name="question9" value="D">
<span class="checkmark"></span>
</label>
</fieldset><br></div>
</div>
<br>
</div>
<div style="text-align:center">
<button id="next">Next</button>
<button id="submit">Submit</button>
</div>
<script src="javascript.js">
</script>
答案 0 :(得分:0)
我修复了它,因为你没有显示你的HTML代码,我认为你搞砸了标记,而事件监听器中的那些错误参数是为了防止事件冒泡。关于那里的更多信息,What is event bubbling and capturing?
<html>
<head>
<title>Test</title>
<meta charset="utf-8">
</head>
<body>
<button id="submit">Submit</button>
<button id="next">Next</button>
</body>
<script type="text/javascript" src="js.js"></script>
</html>
var slideIndex = 1;
var submit = document.getElementById('submit');
var next = document.getElementById('next');
function showSlides(index){
console.log(index);
}
function returnScore(){
alert("Your Score is "+ getScore()+"/100");
alert('What ever')
}
showSlides(slideIndex);
function plusSlides() {
console.log('Whatever')
showSlides(slideIndex ++);
}
submit.addEventListener("click", returnScore, false);
next.addEventListener("click", plusSlides, false);