網站首頁 編程語言 正文
jquery頁面加載完成后執行某方法
alert("頁面加載完成!");
});?
其對應的完整形態為:
$(document).ready(function(){?
? ? alert("頁面加載完成!");
});?
原生JS方法:
window.function(){?
? ? alert("頁面加載完成!");
}
jquery等待特定元素加載再執行相關函數
jQuery.fn.wait = function (func, times, interval) {
? ? var _times = times || 100, //100次
? ? ? ? _interval = interval || 20, //20毫秒每次
? ? ? ? _self = this,
? ? ? ? _selector = this.selector, //選擇器
? ? ? ? _iIntervalID; //定時器id
? ? if( this.length ){ //如果已經獲取到了,就直接執行函數
? ? ? ? func && func.call(this);
? ? } else {
? ? ? ? _iIntervalID = setInterval(function() {
? ? ? ? ? ? if(!_times) { //是0就退出
? ? ? ? ? ? ? ? clearInterval(_iIntervalID);
? ? ? ? ? ? }
? ? ? ? ? ? _times <= 0 || _times--; //如果是正數就 --
? ? ? ? ? ? _self = $(_selector); //再次選擇
? ? ? ? ? ? if( _self.length ) { //判斷是否取到
? ? ? ? ? ? ? ? func && func.call(_self);
? ? ? ? ? ? ? ? clearInterval(_iIntervalID);
? ? ? ? ? ? }
? ? ? ? }, _interval);
? ? }
? ? return this;
}
默認是執行100次,每次間隔20毫秒,最長等待時間是2000毫秒(2秒),如果要一直等待到元素出現,可以將100改成任意負數。
上面這段代碼直接復制過去,調用方法:
$(".buyGoods_guige_goods").wait(function(){BuyNow();})
“.buyGoods_guige_goods”是需要等待出現的元素,“BuyNow()”是出現后需要執行的函數。
原文鏈接:https://blog.csdn.net/qq_42567524/article/details/122926372
相關推薦
- 2022-09-21 Oracle數據庫對象的使用詳解_oracle
- 2022-05-31 Python中用戶輸入與while循環詳情_python
- 2022-09-29 基于PyQt5實現一個無線網連接器_python
- 2022-11-08 hooks中useEffect()使用案例詳解_React
- 2022-08-05 RedisConfig 配置文件
- 2022-06-30 詳解Go語言中泛型的實現原理與使用_Golang
- 2022-10-11 利用React實現虛擬列表的示例代碼_React
- 2022-09-13 Nginx如何配置根據路徑轉發詳解_nginx
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支