javascript - WordPress 未捕获类型错误 : $ is not a function, 想要禁用链接

标签 javascript jquery wordpress

我尝试制作 the following page ,绿色 (1) 事件重定向到另一个页面。这是我正在使用的代码,您可以在第 184 行找到它,它返回 Uncaught TypeError 错误。

<script type="text/javascript">
jQuery(document).ready(function($){
  $('.fc-day-grid-event').click(function(event) {
        var id = $(this).prop('class');
        if (id == 'fc-day-grid-event fc-h-event fc-event fc-start fc-end') {
            event.preventDefault();            
            //i want to prevent
        } else {
            //redirect
        }
    });
});
</script>

谁能告诉我问题出在哪里吗?谢谢

最佳答案

您可以将其包装在 IIFE 语法中:

(function($) { //<-----get the $ alias for jQuery here
  // inside this block $ is secured to use.
  $(document).ready(function() {
    $('.fc-day-grid-event').click(function(event) {
      var id = $(this).prop('class');
      if (id == 'fc-day-grid-event fc-h-event fc-event fc-start fc-end') {
        event.preventDefault();
        //i want to prevent
      } else {
        //redirect
      }
    });
  });
})(jQuery); //<----pass jQuery here

关于javascript - WordPress 未捕获类型错误 : $ is not a function, 想要禁用链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34179550/

相关文章:

javascript - 如何在粘贴 url 后显示 youtube 视频数据,就像 Facebook 的 Wall 表单一样?

javascript - 区分大小写的 GET

javascript - 如何列出 JavaScript 中内置函数的属性?

javascript - 多个输入字段触发的绑定(bind)事件

jQuery - 如何在特定元素下找到具有部分 ID 的元素

WordPress 作为远程发布机制

php - 如何使 $_GET 函数与重写的 url 一起工作?

javascript - 使用 html 5 和 webGL 构建信息模型

javascript - 平滑幻灯片如何在 JavaScript 中工作?

php - 为 WooCommerce 单品添加图片文件上传字段