我有一个简单的jquery点击事件

<script type="text/javascript">
    $(function() {
        $('#post').click(function() {
            alert("test"); 
        });
    });
</script>

以及在site.master中定义的jquery引用

<script src="<%=ResolveUrl("~/Scripts/jquery-1.3.2.js")%>" type="text/javascript"></script>

我已经检查了脚本被正确解析,我能够看到标记,并直接在firebug中查看脚本,所以我必须被发现。然而,我仍然得到:

$没有定义

jquery没有一个是有效的。我还尝试了它的各种变体,比如$(document)。ready和jQuery等。

这是一个。net 3.5上的MVC 2应用程序,我确信我真的很密集,谷歌上的所有地方都说要检查文件是否被正确引用,我已经检查了一遍又一遍,请建议!: /


当前回答

I had this problem once for no apparent reason. It was happenning locally whilst I was running through the aspnet development server. It had been working and I reverted everything to a state where it had previously been working and still it didn't work. I looked in the chrome debugger and the jquery-1.7.1.min.js had loaded without any problems. It was all very confusing. I still don't know what the problem was but closing the browser, closing the development server and then trying again sorted it out.

其他回答

I had this problem once for no apparent reason. It was happenning locally whilst I was running through the aspnet development server. It had been working and I reverted everything to a state where it had previously been working and still it didn't work. I looked in the chrome debugger and the jquery-1.7.1.min.js had loaded without any problems. It was all very confusing. I still don't know what the problem was but closing the browser, closing the development server and then trying again sorted it out.

在解决方案中提到了- 最后一件要检查的事情是确保在加载jQuery之前没有加载任何插件。插件扩展了“$”对象,所以如果你在加载jQuery核心之前加载了一个插件,那么你会得到你所描述的错误。

为了避免这种情况

许多JavaScript库使用$作为函数或变量名,就像jQuery一样。在jQuery的例子中,$只是jQuery的别名,所以所有的功能都可以使用,而不需要使用$。如果我们需要在jQuery旁边使用另一个JavaScript库,我们可以通过调用$.noConflict()将$的控制权返回给另一个库:

我只是做了同样的事情,发现我有很多

type="text/javacsript"

所以他们正在加载,但没有进一步提示为什么它不能工作。不用说,正确的拼写解决了这个问题。

我们有同样的问题....但是我不小心检查了文件夹属性并设置了一些东西…

你必须检查你正在访问的每个文件夹的属性。

右键单击文件夹 “权限”选项卡 设置文件夹访问权限: OWNER:创建和删除文件 GROUP:访问文件 其他:访问文件

我希望这是解决方案......

我在这里没有发现,但确实发生在我身上。请确保您没有包含jQuery精简版,因为该版本的jQuery库不包括Ajax功能。

结果是“$”可以工作,但是$。例如,Get将返回一个错误消息,说明该函数未定义。

解决方案:包含完整版的jQuery。