2016-07-19 46 views
0

我不知道我的代碼有什麼問題。如果我的腳本在jsfiddle中運行,那很好。但如果在我的電腦(本地主機)它不起作用。Myscript不在我的本地主機工作,但如果在jsfiddle這很好

這裏是我的jsfiddle:JSFIDDLE

這裏是我的腳本,我在我的電腦上運行

<html> 
<body> 
<input id="nominal" type="text" /> 
<script> 
$(function() { 
    var money = 20000; 

    $("#nominal").on("change keyup", function() { 
     var input = $(this); 

     // remove possible existing message 
     if(input.next().is("form")) 
      input.next().remove(); 

     // show message 
     if(input.val() > money) 
      input.after("<form method=\"post\" action=\"\"><input type=\"submit\" name=\"yes\" value=\"Yes\"><input type=\"submit\" name=\"no\" value=\"No\"></form>"); 
    }); 
}); 
</script> 
</body> 
</html> 
+1

你需要將jquery包含到你的文件 – scrappedcola

+0

jQuery是否包含在localhost中? –

+0

我必須包含哪些jquery? @scrappedcola –

回答

3

您需要包括jQuery庫使用jQuery功能:

將這個你上面的腳本標記:

<script src="https://code.jquery.com/jquery-3.1.0.slim.js" integrity="sha256-L6ppAjL6jgtRmfiuigeEE5AwNI2pH/X9IBbPyanJeZw=" crossorigin="anonymous"></script> 

<script> 
$(function() { 
    var money = 20000; 

    $("#nominal").on("change keyup", function() { 
     var input = $(this); 

     // remove possible existing message 
     if(input.next().is("form")) 
      input.next().remove(); 

     // show message 
     if(input.val() > money) 
      input.after("<form method=\"post\" action=\"\"><input type=\"submit\" name=\"yes\" value=\"Yes\"><input type=\"submit\" name=\"no\" value=\"No\"></form>"); 
    }); 
}); 
</script> 

它會從CDN i加載jQuery nto你的頁面。

+0

不錯的工作感謝 –

相關問題