TypeError:“未定义"不是仅在Safari中具有Tablesorter的功能 [英] TypeError: 'undefined' is not a function with Tablesorter only in Safari

查看:110
本文介绍了TypeError:“未定义"不是仅在Safari中具有Tablesorter的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在野生动物园中出现错误:

Only in safari I get the error:

TypeError:未定义不是函数(正在评估'$("table").tablesorter')

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

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

In all other browsers it works. This is my javascript code, and I have putt in the header the scripts to jquery and the tablesorter javascript. So how can i solve this problem? And why is it only in Safari and not in any other browser?

 <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的第一个副本相关联(

When jQuery is loaded twice, any scripts that are loaded between the two copies get associated with the first copy of 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的第二个副本.

So once the document ready function is called, the jQuery calls inside refer to the second copy of jQuery that was loaded.

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

If this situation is unavoidable, then you'll need to define a variable associated with the first copy:

<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>

请参考此jQuery论坛帖子更多细节.

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

In addition, I would report this issue to your web host, as they should be checking to see if jQuery already exists before loading it.

这篇关于TypeError:“未定义"不是仅在Safari中具有Tablesorter的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆