首页 > 解决方案 > jQuery加载文件不起作用,空白页?

问题描述

我正在尝试导入文件的内容(文件本身并不重要,html、php、文本)-在所有情况下,我都无法加载任何内容。我什至使用了直接复制过去教程,它不加载或工作?我想我错过了一些东西,或者可能存在版本冲突?

HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>test</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">

 <script type="text/javascript">
   jQuery(document).ready(function(){
       jQuery("#new").load("new.html);
   });
</script>
</head>
<body>
 
<div id="new"></div>
 
</body>
</html>

这段代码直接取自 jQuery 网站,我只是将要加载的文件更改为“new.html”,是的,我在同一个目录中有那个命名文件。我已经尝试过从在线引用源代码和使用本地 jquery 文件,也尝试过不同的浏览器。

测试时,浏览器显示一个空白页面,它不显示文本?。

任何想法我做错了什么?

谢谢,

标签: javascripthtmljquery

解决方案


你应该这样做而不是JQuery

$(document).ready(function(){
   $("#new").load("new.html");
});

// OR

$(function(){
  $("#new").load("new.html");
)};

我建议使用

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

这不起作用的原因是它JQuery已被弃用(意味着它不应该被使用并且大部分时间都会出错)你应该使用$它,因为它没有被弃用并且是新的方法。你也load("new.html)错过了额外的"


推荐阅读