我在我的脚本中使用它:
$.fn.dataTableExt.oSort['title-numeric-asc'] = function(a,b) {
var x = a.match(/title="*(-?[0-9\.]+)/)[1];
var y = b.match(/title="*(-?[0-9\.]+)/)[1];
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
datatableExt 来自此:
http://datatables.net/download/build/jquery.dataTables.js
有时我包含“jquery.dataTables.js”,有时不包含。
所以如果包含数据表代码,我想添加这个插件。
我该如何检查?
是不是类似 (typeof fn.dataTableExt != 'undefined')
最佳答案
我认为这很简单
if (!$.fn.dataTableExt) {
alert('does not exist');
} else {
alert('does exist');
}
关于jQuery 插件(如果对象存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12304478/