skf*_*lfk 6 javascript safari jquery tablesorter
只有在safari我得到错误:
TypeError:undefined不是函数(评估'$("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
Run Code Online (Sandbox Code Playgroud)
当 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>
Run Code Online (Sandbox Code Playgroud)
因此,一旦调用了文档就绪函数,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>
Run Code Online (Sandbox Code Playgroud)
请参阅此 jQuery 论坛帖子了解更多详细信息。
此外,我会向您的网络主机报告此问题,因为他们应该在加载之前检查 jQuery 是否已经存在。
| 归档时间: |
|
| 查看次数: |
9928 次 |
| 最近记录: |