本文介紹了如何檢查 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 插件和函數是否存在?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!