2015-04-27 66 views
3

我覺得我是goona被問及這個問題的原因。這是我第一次嘗試js(需要的原因)。
爲什麼我只看到了所有人的警報Always沒有出現Javascript提醒

<script src="./js/jquery-1.11.2.min.js">alert("Never, but should it?");</script> 
<script>alert("Always");</script> 
<script> 
    alert("Never"); 
    $(document).ready(function(){ 
     alert("Never"); 
     $('#send').click(function() { 
      alert("Never"); 
      $.post('index.py', {document.getElementById('input_text').value}, function(data){ 
       alert("Never"); 
       $('loader').html(data); 
      }) 
     }) 
    }) 
</script> 
+0

你得到的頁面上的任何錯誤?你確定jquery被加載了'。/ js/jquery-1.11.2.min.js' – Huangism

+0

我確定jQuery在那裏。錯誤!語法,如在傢伙的答案中。 – Aero

回答

4

如果您在script標籤提供src,那麼標籤內的JavaScript將不被執行。之後,第一個提醒是Always,所以你會看到特定的提醒。

第三個腳本包含語法錯誤這就是爲什麼你不看點擊OKAlways警報後Never警報

更換

$.post('index.py', {document.getElementById('input_text').value}, function(data){ 

$.post('index.py', document.getElementById('input_text').value, function(data){ 
3

的第一個腳本包含一個src屬性,該屬性預置了內容。

the MDN來自:

該屬性指定外部腳本的URI;可以使用 作爲將腳本直接嵌入到 文檔中的替代方法。與SRC腳本元素屬性指定不應 有一個腳本嵌入其標籤

第三個腳本內未執行,因爲有一個語法錯誤。

而不是

$.post('index.py', {document.getElementById('input_text').value}, function(data){ 

你可能想

$.post('index.py', document.getElementById('input_text').value, function(data){