Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery插件文件加载但不起作用_Javascript_Jquery_Plugins_Tablesorter - Fatal编程技术网

Javascript JQuery插件文件加载但不起作用

Javascript JQuery插件文件加载但不起作用,javascript,jquery,plugins,tablesorter,Javascript,Jquery,Plugins,Tablesorter,我正在尝试加载tablesorter JQuery插件,我使用的是JQuery版本2.1.1和最新版本的tablesorter。我按以下顺序加载它们: <script src="javascript/jquery-2.1.1.min.js"></script> <script src="javascript/jquery.tablesorter.min.js"></script> 在文件的顶部,这在页面加载时起作用 所有插件功能都不起作用,我使用

我正在尝试加载tablesorter JQuery插件,我使用的是JQuery版本2.1.1和最新版本的tablesorter。我按以下顺序加载它们:

<script src="javascript/jquery-2.1.1.min.js"></script>
<script src="javascript/jquery.tablesorter.min.js"></script>
在文件的顶部,这在页面加载时起作用

所有插件功能都不起作用,我使用以下代码对其进行了测试:

$(document).ready(function(e){
  if(jQuery.fn.tablesorter){
    alert("pluginloaded");
   }
     jQuery.tablesorter();
   }
}

警报不起作用,firebug报告tablesorter不是一个函数。

我认为这个问题是多个问题的组合

  • document ready函数没有右括号,这导致javascript错误,使函数根本无法运行:

    $(document).ready(function(e){
        if (jQuery.fn.tablesorter) {
            alert("pluginloaded");
        }
        jQuery.tablesorter();
    });
    
  • 第二个问题是没有正确调用tablesorter。行
    jQuery.tablesorter()
    试图调用tablesorter函数,但这只是一个包含所有tablesorter插件函数的对象

    要真正调用插件,需要使用jQuery选择器,后跟tablesorter函数(这就是为什么
    jQuery.fn.tablesorter
    可以工作的原因——这很简单)


  • 查看文件的路径,听起来好像找不到文件。通过查看Firebug中的“网络”选项卡检查文件是否正在加载来验证这一点。文件肯定正在被找到,正如我所说,我在其中放置了一个警报,触发了
    $(document).ready(function(e){
        if (jQuery.fn.tablesorter) {
            alert("pluginloaded");
        }
        jQuery.tablesorter();
    });
    
    $(function (e) {
        if (jQuery.fn.tablesorter) {
            alert("pluginloaded");
        }
        // jQuery.tablesorter(); // not the way to call the plugin
        $('table').tablesorter();
    });