How to check jQuery plugin and functions exists?(如何检查 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 插件和函数是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检查 jQuery 插件和函数是否存在?
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01