我的jQuery不能在我的网页上工作 [英] My jQuery Won't Work on my Webpage

查看:140
本文介绍了我的jQuery不能在我的网页上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所有的HTML和CSS代码都能正常工作,并且我的脚本已正确链接(或者我假设),但无法加载脚本或执行任何我编写的操作。这是我的HTML,CSS和JS代码:

All of my HTML and CSS code works fine, and my script is properly linked (or so I assume), but I can't get the script to load or do any actions I've coded. Here's my HTML, CSS, and JS code:

HTML

<!DOCTYPE html>
<html>
<head>
    <title>Highlights</title>
    <link rel='stylesheet' type='text/css' href='testwebcss.css'/>
    <script type='text/javascript' src='testwebjs.js'></script>

</head>
        <body>
    <div id="title" class="highlighted">I'm highlighted!</div>
    <div id="text">Highlight me, too!</div>
        </body>
    </html>

CSS

#title {
background-color: #C02942;
border-radius: 5px;
text-align: center;
font-family: Verdana, Arial, Sans-Serif;
color: #FFFFFF;
width: 200px;
height: 25px;
}

#text {
background-color: #0B486B;
border-radius: 5px;
text-align: center;
font-family: Vivaldi, Cursive;
color: #FFFFFF;
width: 200px;
height: 25px;
opacity: 0.5;
}

.highlighted {
-webkit-box-shadow: 0 0 8px #FFD700;
-moz-box-shadow: 0 0 8px #FFD700;
box-shadow: 0 0 8px #FFD700;
cursor:pointer;
}

JS

$(document).ready(function(){
$('#text').mouseenter(function(){
    $(this).fadeTo('fast', 1);
});

$('#text').mouseleave(function(){
    $(this).fadeTo('fast', 0.5);
});
});

所以我不明白为什么它不起作用。正如你所看到的,当鼠标进入#text的边界时,脚本只会使不透明度加倍。那么,为什么没有工作。我从控制台得到了这个:

So I don't understand why it's not working. As you can see, the script simply doubles the opacity when the mouse enters the perimeter of #text. So, why is nothing working. I got this from the console:


未捕获的ReferenceError:$未定义


推荐答案

将其添加到HTML头(在包含脚本之前):

Add this to the HTML head (before you include your script):

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

这篇关于我的jQuery不能在我的网页上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆