为什么不安装jQuery? [英] Why isn't jQuery installing?

查看:80
本文介绍了为什么不安装jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!doctype html>
<html>
<head>
<title>jQuery install test</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

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

<style type="text/css"></style>

</head>

<body>

<script>

    if (typeof jQuery != "undefined"){
        alert("jQuery is installed");
    } else {
        alert("jQuery is not installed");
    }

</script>

</body>
</html>

由于某种原因,我无法嵌入jQuery.我将下载的jquery.min.js命名为jQuery文件.我还尝试将src更改为" http://ajax.googleapis.com /ajax/libs/jquery/latest/jquery.js ",但效果不佳.我的代码有问题吗?我是编程新手.

For some reason I am unable to embed jQuery. I named the jQuery file I downloaded jquery.min.js. I also tried changing the src to "http://ajax.googleapis.com/ajax/libs/jquery/latest/jquery.js" but that didn't work as well. Is there a problem with my code? I am new to programming.

推荐答案

鉴于上面的HTML,要检查的事情:

Things to check, given your HTML above:

1)JQuery文件必须与HTML文件位于Web应用程序的同一文件夹中(如果您已将其下载到应用程序的根目录中,则确定没有放入"scripts"文件夹中)您需要在src属性的前面加上一个"/".

1) JQuery file must be in the same folder in your web app as your html file (are you sure you didn't put in the the "scripts" folder - if you've downloaded it into the root of your app you'll need a "/" at the front of the src attribute.

2)在浏览器中检查您的控制台-查看其中是否显示红色

2) Check your console in the browser - see if there's something showing red in there

4)在您的浏览器中,转到代码"watch"(使用chrome,这是最简单的浏览器,用于执行IMO,有些人则相反)-并添加"$"和"jQuery"的手表-看看结果如何.

4) In your browser, go to the code "watch" bit (use chrome for this, simplest browser for doing this sort of thing IMO, tho some people think otherwise) - and add watches for "$" and "jQuery" - see what comes out.

3)下载 FIDDLER -这将使您准确了解浏览器的需求-可能是'jquery文件请求将看到404. (实际上,这是了解该问题以外的一种非常有用的工具-特别是如果您是Web开发人员的新手,并且经常会花一会儿的时间)

3) Download FIDDLER - this will let you see exactly what's being demanded by the browser - likely you'll see a 404 for the jquery file request. (It's actually a really good tool to get to know outside of this issue - esp if you're new to web dev and will often be scratching your head for a while)

FWIW-HTML看起来很不错-有点像"src"中的错误路径或文件名拼写错误的东西.

FWIW - the HTML looks broadly fine - it'll be something silly like a wrong path in the "src" or mis-spell int he file name.

HTH

这篇关于为什么不安装jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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