我是 jQuery 的新手。在使用 jQuery 时,我断开了 Internet 连接以检查我的网页在没有 Internet 连接的情况下是否正常工作。它显示了一些不需要的东西。当我看到源代码时,它显示:
<link rel="stylesheet" href="http://jquery.com/jquery-wp-content/themes/jquery/css/base.css?v=1">
所以我下载了代码并将其保存在我的根文件夹中。仍然效果不佳。我们可以离线使用 jQuery 吗?
这是我的代码:
<!doctype html>
<!-- [if IE 7 ]> <html class="no-js ie ie7 lte7 lte8 lte9" lang="en-US"> <![endif] -->
<!-- [if IE 8 ]> <html class="no-js ie ie8 lte8 lte9" lang="en-US"> <![endif] -->
<!-- [if IE 9 ]> <html class="no-js ie ie9 lte9>" lang="en-US"> <![endif] -->
<!-- [if (gt IE 9)|!(IE)]> <!-- > <html class="no-js" lang="en-US"> <!--<![endif] -->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title> Home</title>
<meta name="author" content="jQuery Foundation - jquery.org">
<meta name="description" content="jQuery: The Write Less, Do More, JavaScript Library">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="http://jquery.com/jquery-wp-content/themes/jquery/css/base.css?v=1">
<script src="jquery.min.js"></script>
<!--[if lt IE 7]><link rel="stylesheet" href="css/font-awesome-ie7.min.css"><![endif]-->
<script>try{Typekit.load();}catch(e){}</script>
<meta name="generator" content="WordPress 3.5.1" />
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an outdated browser.
<a href="http://browsehappy.com/">Upgrade your browser today</a>
or <a href="http://www.google.com/chromeframe/?redirect=true">install
Google Chrome Frame</a> to better experience this site.</p>
<![endif]-->
<header>
<section id="global-nav">
<nav>
<div class="constrain">
<ul class="links">
<li><a href="home.jsp">Home</a></li>
<li class="dropdown"><a href="CreatPatient.jsp">Patient</a>
<ul>
<li><a href="CreatePatient.jsp">Create Patient</a></li>
<li><a href="Edit Patient">Edit Patient</a></li>
</ul>
</li>
<li class="dropdown"><a href="Appointments.jsp">Appointments</a>
<ul>
<li><a href="CreateAppointments.jsp">Create Appointments</a></li>
<li><a href="EditAppointments.jsp/">Edit Appointments</a></li>
</ul>
</li>
<li class="dropdown"><a href="#">Reports</a>
<ul>
<li><a href="PreOperative.jsp">Pre Operative</a></li>
<li><a href="IntraOperative.jsp">Intra Operative</a></li>
<li><a href="PostOperative.jsp">PostOperative</a></li>
</ul>
</li>
</ul>
</div>
</nav>
</section>
</header>
</body>
</html>
当我删除这一行时:
<link rel="stylesheet" href="http://jquery.com/jquery-wp-content/themes/jquery/css/base.css?v=1">
这会产生问题。
我已经下载了 jQuery 并保存在桌面上。 HTML 文件也在桌面上。为什么它不起作用?
最佳答案
是的,这是可能的。您已经提到您下载了该文件 - 这是一个很好的第一步,但您还必须更改所有 href
和 src
引用资料。
例如,
<link rel="stylesheet" href="http://jquery.com/jquery-wp-content/themes/jquery/css/base.css?v=1">
应该变成
<link rel="stylesheet" href="base.css">
还要记得获取 jQuery JS 库的离线版本:
下载 jquery.js ,把它放在你的根文件夹中并引用它:
<script src="jquery-1.9.1.min.js"></script>
如果你想把它放在子目录中:
<script src="[subdirectory-name]/jquery-1.9.1.min.js"></script>
请记住,这两个文件 都需要离线并位于您的工作本地目录中。这意味着您不能删除样式表也不能jQuery JS 库。以我上面提到的本地格式保留它们。
此外,将 <script>
<head>
中的标签是不好的做法;把它移到 </body>
之前改为标记。
您的代码现在应该看起来(简而言之,请注意我没有放太多):
...
<html class="no-js" lang="en-US">
<head>
...
<link rel="stylesheet" href="base.css">
...
</head>
<body>
...
<script src="jquery.min.js"></script>
</body>
</html>
再次确保 base.css
和 jquery.min.js
是确切的文件名 并且与此.html
在同一文件夹中文件
关于javascript - 在没有 Internet 连接时使用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15872414/