Include js 的結束Tag會造成奇怪問題

  • 2897
  • 0

Include js 的結束Tag會造成奇怪問題

Dotblogs 的標籤: , ,

今天被這個怪問題打到……


<html>
<head>
<title>test by leo</title>
    <script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(function() { //nothing
         });
         
        function test() {
            alert("here");
        }
    </script>
</head>
<body>
    <script language="javascript" type="text/javascript">        
        if (confirm("are you sure")) { test();     } else     { alert("false"); }
    </script>
</body>
</html>

若把上述第 4 行改成:

   1: <script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript" />

當 confirm 按確定,要調用 test() ,就會出現未定義的錯誤…但是若不要在 confirm 中呼叫 test(),jQuery 相關功能還是可以正常作業。

原因不明,但是今天被這個問題搞了四、五個小時,氣死…

有那位先進可以告訴我原因嗎?

--------
沒什麼特別的~
不過是一些筆記而已