0
我有兩個鏈接到一個html文件的JavaScript文件,根據我放置它們的順序,第二個不起作用。第二個腳本文件不起作用
HTML:
<head>
<title>J2EE</title>
<meta charset="utf-8"/>
<meta name="description" content="J2EE quiz page"/>
<meta name="keywords" content="html, j2ee, J2EE"/>
<meta name="author" content="Wing Hang Khoo"/>
<!-- Reference to external style -->
<link href="styles/styles.css" rel="stylesheet"/>
<script src="scripts/enhancements.js"></script>
<script src="scripts/quiz.js"></script>
</head>
JS 1:
function x(){
*validating questions codes*
}
function init(){
var regForm = document.getElementById("regForm");
regForm.onsubmit = gradeTest;
}
window.onload = init;
JS 2:
function y(){
*timer code*
}
window.onload = function() {
var fiveMinutes = 60 * 5,
display = document.querySelector('#time');
startTimer(fiveMinutes, display);
};
不知道這是因爲兩者都具有window.onload
功能。
屬性只能保存一個值。您不能將兩個函數分配給'window.onload'。改用'.addEventListener'。 –