我尝试制作 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/