gpt4 book ai didi

javascript - 类型错误 : 'undefined' is not a function with Tablesorter only in Safari

转载 作者:数据小太阳 更新时间:2023-10-29 05:10:19 26 4
gpt4 key购买 nike

只有在 safari 中我才会收到错误:

TypeError: undefined is not a function (evaluating '$("table").tablesorter')

在所有其他浏览器中它都有效。这是我的 javascript 代码,我在标题中放入了 jquery 脚本和 tablesorter javascript。那么我该如何解决这个问题呢?为什么它只在 Safari 而不是在任何其他浏览器中?

 <script>

$(function() {

// call the tablesorter plugin
$("table").tablesorter({
theme : 'jui',
headerTemplate : '{content}{icon}',
// hidden filter input/selects will resize the columns, so try to minimize the
etc

最佳答案

当 jQuery 被加载两次时,在两个副本之间加载的任何脚本都会与 jQuery 的第一个副本相关联(ref):

<script src="jquery-copy1.js"></script>
<script src="myPluginExtendedFromJQ1.js"></script>

<script src="jquery-copy2.js"></script>
<script src="myPluginExtendedFromJQ2.js"></script>

<script>
// all of the jQuery's below are associated with jquery-copy2
jQuery(function(){
// no problems
jQuery('#demo-x').myPluginExtendedFromJQ2();

// error: myPluginAttachedTOJQ1 is undefined
jQuery('#demo-y').myPluginExtendedFromJQ1();
});
</script>

因此,一旦文档就绪函数被调用,内部的 jQuery 调用将引用加载的 jQuery 的第二个副本。

如果这种情况不可避免,那么您需要定义一个与第一个副本关联的变量:

<script src="jquery-copy1.js"></script>
<script>var $jq1 = jQuery.noConflict();</script>
<script src="myPluginExtendedFromJQ1.js"></script>

<script src="jquery-copy2.js"></script>
<script src="myPluginExtendedFromJQ2.js"></script>

<!-- other stuff -->
<script>
// lets call plugins attached to the first copy of jQuery
// document ready can be called on either version $(function(){ ... })
jQuery(function(){
// no problems
jQuery('#demo-x').myPluginExtendedFromJQ2();

// target first copy of jQuery
$jq1('#demo-y').myPluginAttachedToJQ1();
});
</script>

请引用this jQuery forum post了解更多详情。

此外,我会向您的虚拟主机报告此问题,因为他们应该在加载 jQuery 之前检查它是否已经存在。

关于javascript - 类型错误 : 'undefined' is not a function with Tablesorter only in Safari,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22570548/

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