[英]Separate Javascript file not Functioning
美好的一天,我剛剛制作了一個簡單的javascript文件。 我唯一的問題是警報沒有彈出。 有任何想法嗎? 任何評論表示贊賞,謝謝。
html文件:
<html>
<head>
<script src="practice2.js"></script>
<title>Practice</title>
</head>
<body>
<h1>Title</h1>
<p>sample paragraph</p>
<ul>
<li>List 1</li>
<li>List 2</li>
<li>List 3</li>
</ul>
</body>
</html>
javascipt文件:
var year = 2018;
function myFunction() {
if ( year == 2018 )
{
alert("it is equal to 2018");
}
}
您只需定義您的函數需求就可以像下面這樣調用函數:
var year = 2018; function myFunction() { if ( year == 2018 ) { alert("it is equal to 2018"); } } myFunction();// call your function
試試這個:-您錯過了調用該函數的時間
var year = 2018; function myFunction() { if ( year == 2018 ) { alert("it is equal to 2018"); } }
<html> <head> <script src="practice2.js"></script> <title>Practice</title> </head> <body> <h1>Title</h1> <p>sample paragraph</p> <ul> <li>List 1</li> <li>List 2</li> <li>List 3</li> </ul> <input type="submit" value="Call Function" onclick="myFunction()"/> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.