如何检查jQuery插件和函数是否存在? [英] How to check jQuery plugin and functions exists?

查看:182
本文介绍了如何检查jQuery插件和函数是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某些页面中有一个插件,但在其他一些页面中我不想要它,所以我没有引用它的脚本文件。

I have a plugin in some pages but in some other pages I don't want it so I didn't reference its script file.

如何在使用之前检查插件功能是否存在。

How to check if the plugin functions exist before using it.

在我的情况下我使用的是这个插件:我这样使用它:

In my case I am using this plugin: and I use it like this:

$('#marquee-inner div').marquee('pointer').mouseover(function() {
    $(this).trigger('stop');
}).mouseout(function() {
    $(this).trigger('start');
}).mousemove(function(event) {
    if ($(this).data('drag') == true) {
        this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
    }
}).mousedown(function(event) {
    $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
}).mouseup(function() {
    $(this).data('drag', false);
});

我想要的是在调用此选框函数之前进行检查(如果存在或不存在)。

What I want is to make a check before calling this marquee function if it exist or not.

推荐答案

if ($.fn.marquee) {
    // there is some jquery plugin named 'marquee' on your page
}

这篇关于如何检查jQuery插件和函数是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆