本地jQuery.js文件无法正常工作 [英] Local jQuery.js file not working

查看:63
本文介绍了本地jQuery.js文件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从jQuery.com下载了jQuery.js文件。我已经将这个文件保存在3个地方,包括JRE / Lib和桌面(我调用它的HTML文件),以确保jQuery.js文件找到了。我将此js文件引用为:

I had downloaded jQuery.js file from jQuery.com .I have saved this file in 3 places, including JRE/Lib and desktop (where my HTML file which calls it is), to be sure that the jQuery.js file is found. I reference this js file as :

<head>
        <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
        $(function(){
            $("#clas").click(function(){
                $(this).hide();
            });
        });
    </script>
</head>

<body>
    <p id="clas"> Hello</p>
    <p>Hi</p>
</body>

当我在Mozilla浏览器上运行这个HTML文件时,我希望当我点击时Hello消失它,但它没有。它仍然像以往一样坚固。
但是当我使用jQuery CDN时:

When I ran this HTML file on Mozilla browser, I expected 'Hello' to vanish when I clicked on it, but it did not. It remained as solid as ever. But when I used a jQuery CDN:

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

当我在网上使用时HTML编辑器名为Tryit Editor v1.5,它工作正常!
似乎只有本地jQuery.js没有发挥作用。 JavaScript工作正常,只有$()部分没有。我正在使用jdk1.6。我想知道为什么会发生这种障碍。怎么解决?帮助。

And when I used an online HTML editor called Tryit Editor v1.5, it worked correctly! It seems only the local jQuery.js is not doing its part. The JavaScript works fine, only the $() part doesn't. I'm using jdk1.6. I wonder why this snag has occurred. How to resolve it? Help.

推荐答案

谢谢!我找到了这个问题的解决方案,来自一年前在这个论坛上发布的类似问题。这是链接:

Thanks! I found the solution to this problem, from a similar question posted in this forum, asked a year ago. Here is the link:

如果我使用的是本地jquery.js文件,jQuery代码不起作用,为什么?

问题似乎是html和js文件的编码不兼容。所以我将charset属性添加到js的script标签中。问题和你好都在点击时消失了!

The problem seems to have been incompatible encoding of the html and the js files. So I added the charset attribute to script tag of js. And the problem and 'Hello' both vanished at a click!

这篇关于本地jQuery.js文件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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