最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery block ui getting $.blockUI is not a function - Stack Overflow

programmeradmin1浏览0评论

I have this very simple script of jQuery plugin called blockUI
I found many posts with the same issue but no resolution
Can someone take a look at this snippet or suggest an alternative to blockUI?
Thank you!

function block() {
alert('gonna block')
  $.blockUI();
  setTimeout(unBlock(), 5000); 
}

function unBlock() {
	$.unblockUI();
}

function alertUser() {  
  alert('Alert User'); 
}
<script src=".0.0/jquery.min.js"></script>

<script src=".blockUI/2.70/jquery.blockUI.js"></script>

<button onclick="alertUser()">Alert</button>
<button onclick="block()">Block!</button>
<button onclick="unBlock()">UnBlock!</button>

I have this very simple script of jQuery plugin called blockUI
I found many posts with the same issue but no resolution
Can someone take a look at this snippet or suggest an alternative to blockUI?
Thank you!

function block() {
alert('gonna block')
  $.blockUI();
  setTimeout(unBlock(), 5000); 
}

function unBlock() {
	$.unblockUI();
}

function alertUser() {  
  alert('Alert User'); 
}
<script src="https://cdnjs.cloudflare./ajax/libs/jquery/3.0.0/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare./ajax/libs/jquery.blockUI/2.70/jquery.blockUI.js"></script>

<button onclick="alertUser()">Alert</button>
<button onclick="block()">Block!</button>
<button onclick="unBlock()">UnBlock!</button>

Share Improve this question edited Feb 5, 2019 at 18:28 JavaSheriff asked Feb 4, 2019 at 22:05 JavaSheriffJavaSheriff 7,71526 gold badges102 silver badges173 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

You need to include jQuery before you include any plugins.

Change the order of your includes.

It does work but you are calling unblock instantly and it goes away, pass the function into setTimeout instead of calling it.

function block() {
  $.blockUI();
  setTimeout(unBlock, 5000); 
}

function unBlock() {
  $.unblockUI();
}

function alertUser() {  
  alert('Alert User'); 
}
<script src="https://cdnjs.cloudflare./ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/jquery.blockUI/2.70/jquery.blockUI.js"></script>

<button onclick="alertUser()">Alert</button>
<button onclick="block()">Block!</button>
<button onclick="unBlock()">UnBlock!</button>

发布评论

评论列表(0)

  1. 暂无评论