jQuery -- blockUI 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12398461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery -- blockUI is not a function
提问by hec
I have the following jQuery code that is giving me a problem. I have two jQuery functions that both call blockUI, and I get the same error for both. It says that blockUI is not a function. Can anybody tell me why?
我有以下 jQuery 代码给我带来了问题。我有两个 jQuery 函数,它们都调用 blockUI,并且两者都得到相同的错误。它说 blockUI 不是一个函数。谁能告诉我为什么?
function loading() {
// register on click event for buttons.
$.blockUI({
message: '<h3 class="fldHead">Loading... <img src="/app/images/winliveprog.gif"/></h3>'
});
$('body').css('cursor', 'wait');
}
$(function() {
$('[name="btnPreviewPost"]').click(function() {
console.log('btnPreviewPost clicked');
$(this).blockUI();
loading();
$.blockUI({
message: '<h3 class="fldHead">Loading... <img src="/capserver/images/winliveprog.gif"/></h3>'
});
$('body').css('cursor', 'wait');
});
$('[name="btnEditPost"]').click(function() {
console.log('btnEditPost clicked')
$(this).blockUI();
loading();
$.blockUI({
message: '<h3 class="fldHead">Loading... <img src="/capserver/images/winliveprog.gif"/></h3>'
});
$('body').css('cursor', 'wait');
});
});
采纳答案by Brentoe
Try creating it as $.fn.blockUI for calling it on jquery objects like $(this).blockUI();
尝试将其创建为 $.fn.blockUI,以便在像 $(this).blockUI(); 这样的 jquery 对象上调用它。
回答by hec
I had the same problem, turns out I included the javascript file twice through some dependency. Once I removed one of the javascript files, blockUI
worked fine.
我遇到了同样的问题,结果我通过一些依赖项两次包含了 javascript 文件。一旦我删除了其中一个 javascript 文件,blockUI
就可以正常工作。
回答by Matthew Raymond
Note that the jQuery BlockUI plug-in will not function "out of the box" in the latest version of jQuery.This is because BlockUI makes use of the jQuery.browser API, which was removed in jQuery 1.9. To get BlockUI working again, you need to use jquery-migrate:
请注意,jQuery BlockUI 插件在最新版本的 jQuery 中不会“开箱即用”。这是因为 BlockUI 使用了 jQuery.browser API,该 API 在 jQuery 1.9 中已被删除。要让 BlockUI 再次工作,您需要使用 jquery-migrate:
回答by Mithril
You can just use $(element).block();
see here http://www.malsup.com/jquery/block/#element
你可以在$(element).block();
这里使用http://www.malsup.com/jquery/block/#element
回答by Yingbo Cui
I occurred the same problem, and I solved it by including this file:
我遇到了同样的问题,我通过包含这个文件来解决它:
<script src="http://malsup.github.io/jquery.blockUI.js">
回答by Yasith
I had a same issue and the problem was path I used to register blockUI. In my case src of the of the jquery.blockUI.js in site.master page was wrong. Please check whether your are registering jquery.blockUI.js correctly.
我有同样的问题,问题是我用来注册 blockUI 的路径。在我的情况下,site.master 页面中 jquery.blockUI.js 的 src 是错误的。请检查您是否正确注册了 jquery.blockUI.js。
回答by Xiaoxing
I am using the Angular and meeting the same issue here. Inspired by @Robert, I found out there are two references:
我正在使用 Angular 并在这里遇到同样的问题。受到@Robert 的启发,我发现有两个参考文献:
jquery.min.js
jquery.min.js
in the angular.json. I removed one and it worked.
在 angular.json 中。我删除了一个并且它起作用了。
回答by Mike
I my case it was old version (2.0.10) of woocommerce plugin - I couldn't update it because it would break some custom functionality - so I had to comment out jQuery lines with .block in write-panels.min.js and writepanel-product-type-variable.php .
我的情况是它是 woocommerce 插件的旧版本(2.0.10) - 我无法更新它,因为它会破坏一些自定义功能 - 所以我不得不在 write-panels.min.js 和 .block 中注释掉 jQuery 行writepanel-product-type-variable.php 。