×

学习jQuery.holdReady()

作者:abc1232017.09.25来源:Web前端之家浏览:8807评论:0
关键词:JQueryJS

本文实例讲述了jQuery.holdReady()方法用法。分享给大家供大家参考。具体分析如下:

此方法可以暂停或者恢复jQuery.ready()事件。
调用此方法可以延迟jQuery的ready事件,也就是说尽管文档已经加载完成,也不会执行ready事件处理方法。
可以多次调用jQuery.holdReady()方法,以延迟jQuery的ready事件,当满足一定条件时,再通过将此方法的参数设置为false,一一解除延迟。方法一般用于动态脚本加载,知道脚本加载完成然后再通过将此方法的参数设置为false,解除对jQuery.ready()事件延迟。

语法结构:

jQuery.holdReady(hold)

参数列表:

参数 描述
hold 如果值为true,则会延迟jQuery.ready()事件。
 如果值为false,则会解除对jQuery.ready()事件延迟。

如果值为false,则会解除对jQuery.ready()事件延迟。

实例代码:

实例一:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="https://www.jiangweishan.com/" /> 
<title>脚本之家</title> 
<script type="text/javascript" src="/demo/js/jq.js"></script> 
<script type="text/javascript"> 
jQuery.holdReady(true); 
$(document).ready(function(){ 
  alert("我不会被弹出"); 
}) 
</script> 
</head> 
<body> 
   
</body> 
</html>

在以上代码中,由于添加了 jQuery.holdReady(true),所以尽管文档加载完成,也不会执行ready()中的函数。
实例二:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="https://www.jiangweishan.com/" />
<title>脚本之家</title> 
<script type="text/javascript" src="/demo/js/jq.js"></script>  
</head> 
<body> 
<button id="first">点击测试弹出</button>
<button id="second">解除延迟</button> 
<script type="text/javascript"> 
jQuery.holdReady(true)  
$(document).ready(function(){ 
  $("#first").click(function(){ 
    alert("我不会被弹出"); 
  }) 
}) 
$("#second").click(function(){ 
  jQuery.holdReady(false); 
}) 
</script>
</body> 
</html>

当点击解除延迟之后,就可以弹出了。

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/svg1488211200519.html

网友评论文明上网理性发言 已有0人参与

发表评论: