我有2個腳本塊(寫在同一個文件中),但是我無法調用寫在另一個腳本塊中的函數。無法從另一個腳本塊調用javascript函數
<!DOCTYPE html>
<html>
<head>
<title>Just A Test</title>
</head>
<body>
<div class="app">
<h1>Just A Test</h1>
</div>
<div data‐role="main" class="ui‐content">
<form name="testForm" id="testForm">
<div class="ui‐field‐contain">
First greeting:
<script type="text/javascript">
greetings1(); //ERROR AT THIS LINE
</script>
<p></p>
</div>
</form>
</div>
<script type="text/javascript">
function greetings1(){
alert("Hello ONE");
}
</script>
</body>
</html>
我得到的錯誤是:
Error: 'greetings1' is undefined
我的問題是:是什麼原因造成不能夠看到聲明的函數瀏覽器?我花了幾個小時,嘗試了將腳本塊移到head
的方法,但問題仍然存在。
羽絨選民,謹慎解釋?這在之前沒有被問到過。我知道這是一個基本問題,但我花了很多時間在這方面進行研究,我對此很陌生,所以請。 – user3437460
我也不明白。這是一個很好的清晰的問題,並且有明確的答案。 +1。如果這個地方有重複,請投票結束或標記。 –