Firebug给我一个错误,指出“未定义$(70超出范围28)”
我不明白为什么,因为代码无论如何都能正常执行。该代码查找具有“like”类的div,单击该div会将值发送到ajax。以下是相关代码:
<div class="post" id="post-<?php the_ID(); ?>">
<div id="post-<?php the_ID(); ?>-inside" class="inside">
<div id="like_<?php the_ID(); ?>" class="like" style="position:absolute; right: 2.5em;">
<a id="likebtn_<?php the_ID(); ?>" class="likeimgoff" href="#"><span></span></a>
</div>
</div>
</div>
$(document).ready(function() {
likestatus = 1;
dislikestatus = 1;
$(document).on("click", ".like", function(){
postID = $(this).attr('id').replace('like_', '');
有问题的特定行是这样的:
postID = $(this).attr('id').replace('like_', '');
实际上,已为postID变量分配了适当的值,因此我不理解该错误的原因。有人知道发生了什么吗?
最佳答案
它们可能是冲突的库,例如Prototype等。如此处所述:jQuery works on my page, but firebug says $ is not defined error. Why and how to avoid it?
尝试将$更改为jquery,例如:jQuery(document).ready(...
另外,再次检查您的脚本是否在加载jquery的<script>
行之后。
关于javascript - jQuery ajax $没有定义,但是仍然可以正确执行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8114602/