我已经很好地加载了jQuery,我已经判断了四次,尽管我在Firebug中收到了这个错误"$is not a function",并且我的代码不能工作.

Here's my code:

<script type="text/javascript">
    $("ol li:nth-child(1)").addClass('olli1');
    $("ol li:nth-child(2)").addClass("olli2");
    $("ol li:nth-child(3)").addClass("olli3");
    $("ol li:nth-child(4)").addClass("olli4");
    $("ol li:nth-child(5)").addClass("olli5");
    $("ol li:nth-child(6)").addClass("olli6");
    $("ol li:nth-child(7)").addClass("olli7");
    $("ol li:nth-child(8)").addClass("olli8");
    $("ol li:nth-child(9)").addClass("olli9");
    $("ol li:nth-child(10)").addClass("olli10");
    $("ol li:nth-child(11)").addClass("olli11");
    $("ol li:nth-child(12)").addClass("olli12");
    $("ol li:nth-child(13)").addClass("olli13");
    $("ol li:nth-child(14)").addClass("olli14");
    $("ol li:nth-child(15)").addClass("olli15");
    $("ol li:nth-child(16)").addClass("olli16");
    $("ol li:nth-child(17)").addClass("olli17");
    $("ol li:nth-child(18)").addClass("olli18");
    $("ol li:nth-child(19)").addClass("olli19");
    $("ol li:nth-child(20)").addClass("olli20"); 
</script>

推荐答案

In Wordpress jQuery.noConflict() is called on the jQuery file it includes (scroll to the bottom of the file it's including for jQuery to see this), which means $ doesn't work, but jQuery does, so your code should look like this:

<script type="text/javascript">
  jQuery(function($) {
    for(var i=0; i <= 20; i++) 
      $("ol li:nth-child(" + i + ")").addClass('olli' + i);
  });
</script>

Jquery相关问答推荐

如何在html css中制作响应表

Twitter Bootstrap 是否包含 jQuery?

JQuery通过类名获取所有元素

jQuery 绑定点击 *ANYTHING* 但 *ELEMENT*

如何制作 AngularJS 指令来停止传播?

用jquery查找div底部的位置

如何使用 jQuery go 除 HTML 标签?

调整浏览器大小时调整jqGrid的大小?

JQUERY UI Accordion 开始折叠

如何在 JQuery DataTable 中默认显示所有行

jquery获取帖子操作网址

如何使用 Twitter Bootstrap 弹出框进行 jQuery 验证通知?

将参数附加到 URL 而不刷新

使用 jQuery 验证插件自定义日期格式

Twitter Bootstrap css 类的 jQuery show() 隐藏

JQuery:如果 div 可见

使用 jQuery 比较两个 Javascript 对象数组

如何删除集中的 contenteditable pre 周围的边框?

自调用函数前的分号?

在 Javascript/jQuery 中,(e) 是什么意思?