簡體   English   中英

Jquery 文件未在瀏覽器上加載

[英]Jquery file not loading on browser

當我在谷歌瀏覽器上打開 html 文件時。 它只是一個空白頁。 什么都沒有加載。 如果我取出 .js 文件,它會加載應用了 .css 的內容,但從不加載 .js 文件。 無論我將 .js 文件放在 .js 文件中還是放在它的末尾,它仍然沒有顯示任何內容。 我正在使用 jquery btw 並下載了該文件。 所有文件都在同一個文件夾中。 如果有所不同,還嘗試了 jquery-3.3.1.min.js 和 jquery-migrate-1.4.1.js。 希望有人能幫忙。 謝謝!

HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="testing.css">
</head>
<body>
<div id="products">
  <h1 class="ui-widget-header">Blocks</h1>
  <div class="ui-widget-content">
    <ul>
      <li data-id="1" class="credit"> 10000$ </li>
      <li data-id="2" class="debit"> -10000$ </li>
      <li data-id="3" class="credit"> 10000$ </li>
      <li data-id="4" class="credit"> -10000$ </li>
      <li data-id="5" class="credit"> Bank </li>
      <li data-id="6" class="debit"> Loan </li>
    </ul>
  </div>
</div>

<div id="shoppingCart1" class="shoppingCart">
  <h1 class="ui-widget-header">Credit Side</h1>
  <div class="ui-widget-content">
    <ol>
      <li class="placeholder">Add your items here</li>
    </ol>
  </div>
</div>
<div id="shoppingCart2" class="shoppingCart">
  <h1 class="ui-widget-header">Debit side</h1>
  <div class="ui-widget-content">
    <ol>
      <li class="placeholder">Add your items here</li>
    </ol>
  </div>
</div>


<script type="text/javascript" src="jquery-migrate-1.4.1.js"></script>
<script type="text/javascript" src="testing.js"></script>


</body>
</html>

.JS

$("#products li").draggable({
  appendTo: "body",
  helper: "clone"
});
$("#shoppingCart1 ol").droppable({
  activeClass: "ui-state-default",
  hoverClass: "ui-state-hover",
  accept: ".credit",
  drop: function(event, ui) {
    var self = $(this);
    self.find(".placeholder").remove();
    var productid = ui.draggable.attr("data-id");
    if (self.find("[data-id=" + productid + "]").length) return;
    $("<li></li>", {
      "text": ui.draggable.text(),
      "data-id": productid
    }).appendTo(this);
    // To remove item from other shopping cart do this
    var cartid = self.closest('.shoppingCart').attr('id');
    $(".shoppingCart:not(#" + cartid + ") [data-id=" + productid + "]").remove();
  }
}).sortable({
  items: "li:not(.placeholder)",
  sort: function() {
    $(this).removeClass("ui-state-default");
  }
});
// Second cart
$("#shoppingCart2 ol").droppable({
  activeClass: "ui-state-default",
  hoverClass: "ui-state-hover",
  accept: ".debit",
  drop: function(event, ui) {
    var self = $(this);
    self.find(".placeholder").remove();
    var productid = ui.draggable.attr("data-id");
    if (self.find("[data-id=" + productid + "]").length) return;
    $("<li></li>", {
      "text": ui.draggable.text(),
      "data-id": productid
    }).appendTo(this);
    // To remove item from other shopping chart do this
    var cartid = self.closest('.shoppingCart').attr('id');
    $(".shoppingCart:not(#" + cartid + ") [data-id=" + productid + "]").remove();
  }
}).sortable({
  items: "li:not(.placeholder)",
  sort: function() {
    $(this).removeClass("ui-state-default");
  }
});

.CSS

h1 { padding: .2em; margin: 0; }
#products { float:left; width:200px; height: 600px; margin-right: 20px; }
#products ul {list-style: disc; padding: 1em 0 1em 3em;}
.shoppingCart{ width: 200px; margin: 20px; float: left; }
.shoppingCart ol { margin: 0; padding: 1em 0 1em 3em; list-style-type: decimal;  }

采用

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>

因為jquery-migrate不包含整個jquery代碼。 當然,您可以包含本地腳本。

問題:

  1. 您的HTML文件沒有到jquery和jquery UI的CDN鏈接。 他們需要相同的順序。 首先,您需要jquery CDN和第二個jquery UI cdn
  2. 您在testing.js文件中使用了jquery,但是您沒有document.ready函數。

解決方案:1。為jquery和jquery UI添加cdn鏈接2.在document.ready函數中包裝您的javascript代碼。 這是MDN文檔

您好,每當我鏈接我的任何 jquery 文件時,我的筆記本電腦都會出現錯誤。

“無法訪問您的文件 它可能已被移動、編輯或刪除。”

未找到 ERR 文件

暫無
暫無

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

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