Javascript JQuery插件文件加载但不起作用
我正在尝试加载tablesorter JQuery插件,我使用的是JQuery版本2.1.1和最新版本的tablesorter。我按以下顺序加载它们: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> 在文件的顶部,这在页面加载时起作用 所有插件功能都不起作用,我使用
<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(function(e){
if (jQuery.fn.tablesorter) {
alert("pluginloaded");
}
jQuery.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();
});