gpt4 book ai didi

jquery - “$ 未定义”错误,但 'jQuery' 有效

转载 作者:行者123 更新时间:2023-12-01 06:25:57 25 4
gpt4 key购买 nike

我有这些代码行,它们是错误消息的原因。在我看来,代码没有错误,但我想我错了:

jQuery(document).ready(function() {
console.log("ready!");

$("#hover-table").hover(function() { // THIS IS LINE 164
$('#table-wrapper').show();
}, function() {
$('#table-wrapper').hide();
});
});

我在 Chrome 控制台中收到此错误消息。 console.log 打印没有问题。

(index):164 Uncaught TypeError: $ is not a function
at HTMLDocument. ((index):164)
at i (jquery.js?ver=1.12.4:2)
at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4:2)
at Function.ready (jquery.js?ver=1.12.4:2)
at HTMLDocument.K (jquery.js?ver=1.12.4:2)

我在这里缺少什么?

最佳答案

另一个使用美元符号而不是 jQuery 的库可能会造成此冲突,因此您可以将所有美元符号 $ 替换为 jQuery,如下所示:

<script>
jQuery(document).ready(function() {
console.log("ready!");

jQuery("#hover-table").hover(function() { // THIS IS THE LINE 164---
jQuery('#table-wrapper').show();
}, function() {
jQuery('#table-wrapper').hide();
});
});
</script>

或者您也可以将其定义为内部 block 使用,例如:

jQuery(document).ready(function($){
//You can now use $ as your jQuery object.
});

关于jquery - “$ 未定义”错误,但 'jQuery' 有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52294382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com