繁体   English   中英

为什么我的javascript文件没有链接?

[英]Why isn't my javascript file linking?

这是我第一次尝试使jQuery代码在codeacademy.com以外的其他地方工作,所以请多多包涵。

我在同一个文件夹中有三个文件,即index.html,stylesheet.css和script.js(加上一些图片)。 index.html和style.css相互配合良好,但是无论我输入什么内容,script.js似乎都根本不想要任何效果(命令就像在$(document )。准备...

这是index.html:

<!DOCTYPE HTML>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="stylesheet.css"/>
    <script type='text/javascript' src='script.js'></script>
</head>

<body>
<p>test test test</p>
<div class="mainh1">
    <h1 id="header1">Hi I'm <a href="mailto:redacted@gmail.com" id="email">James</a></h1>
    <h1 id="header2">I live in <a href="www.seattle.gov" id="city">Seattle</a></h1>
    <h1 id="header3">I like <a href="www.makerhaus.com" id="tinker">tinkering</a></h1>
    <h1 id="header4">and I <em>really</em> like <a href="www.analogcoffee.com" id="coffee">coffee</a></h1>
</div>

<div class="image">
    <img src="james.jpg"/>
</div>

<div class="navbar">
</div>

</body>
</html>

这是stylesheet.css:

a {
    text-decoration:none;
}

body {
    background-image: url("debut_light.png");
}
.mainh1 {
    text-align: left;
    font-family: 'Cantora One', sans-serif;
    color: #556270;
    font-size: 25px;
    text-shadow: 0 2px 0 #fff;
    margin: 0;
    margin-top: 75px;
    margin-left: 25px;
    line-height: 150%;
    display: inline-block;
}

#email {
    color: #03738E;
}

#city {
    color: #F1B703;
}

#tinker {
    color: #F15B07;
}

#coffee {
    color: #D92D01;
}

.image {
    height: 400px;
    width: 400px;
    float: right;
    overflow: hidden;
    margin-top: 75px;
    margin-right: 50px;
    border-radius: 20px;
}

.image img {
    width: 100%;
    height: 100%;
}

这是script.js:

$(document).ready( function() {
    $('p').fadeOut('slow');
});

我也尝试链接script.js的整个源路径,并且尝试将其上载到hostgator.com上的服务器无济于事。 知道为什么我的jquery无法正常工作吗? 如果这是一个简单的错误,请多多包涵,这是我编码的第5天。

您尚未加载jQuery。 在加载脚本之前添加以下代码:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

似乎您尚未将jQuery库链接到html文件。 您将需要它来运行jQuery函数,例如$(document).ready()

查看此页面,了解有关如何下载jQuery或从CDN包含jQuery的不同选项。

您正在使用jquery而不将其包含在页面中。

您必须下载jquery脚本文件,例如将其重命名为jquery.js并包含它。

<script language="JavaScript" type="text/javascript" src="/js/jquery.js"></script>

在下载jquery之间和之后添加此选项,它将起作用。

转到jquery.com并下载jQuery :)

http://jquery.com/download/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM