仅在 safari 中我收到错误:
类型错误:未定义不是函数(评估 '$("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>
请参阅这个 jQuery 论坛帖子更多细节。
此外,我会向您的网络主机报告此问题,因为他们应该在加载之前检查 jQuery 是否已存在。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)