簡體   English   中英

我的代碼在<script> tags but doesn't work in an external file

[英]My code works in <script> tags but doesn't work in an external file

只是想知道是否有人可以幫助我。 我遇到了一個從未遇到過的奇怪問題,也不知道如何解決:

<head>
 <title>Welcome to Edge Hill Computing</title>
 <link rel="stylesheet" href="style.css"/>
 <link rel="stylesheet" href="index.css"/>

 <script type="text/javascript" src="global.js"></script>

     <script type = "text/javascript" src="jquery.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
 <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">


</head>

我的JavaScript文件和我的jquery文件都在這里導入。 哪個“應該”到外部jquery文件。 但事實並非如此,我必須使用腳本標簽從那里運行代碼。 有什么解決辦法嗎?

如果它有助於Global.js中的代碼,則是這樣的:

   $(document).ready(function(){
    $("#txtbox").keyup(function(){
        var name = $('#txtbox').val();
     $('#display').html((name));
    });
});

jQuery之后應加載global.js

在jquery腳本引用之后添加腳本標簽。

<head>
 <title>Welcome to Edge Hill Computing</title>
 <link rel="stylesheet" href="style.css"/>
 <link rel="stylesheet" href="index.css"/>
<script type = "text/javascript" src="jquery.min.js"></script>   
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script type="text/javascript" src="global.js"></script>

 <meta name="viewport" content="width=device-width, initial-scale=1"/>
 <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">


</head>
    <head>
     <title>Welcome to Edge Hill Computing</title>
     <link rel="stylesheet" href="style.css"/>
     <link rel="stylesheet" href="index.css"/>
     <script type = "text/javascript" src="jquery.min.js"></script>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
     <script type="text/javascript" src="global.js"></script>
     <meta name="viewport" content="width=device-width, initial-scale=1"/>
     <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">   
   </head>

您需要在加載jquery之后處理您的代碼。 我想象當您將其直接插入頁面時,它位於在head標簽中加載jquery的位置下方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM