我希望在加载页面后禁用javascript函数20秒......
这里启动PHP代码禁用20秒我的代码
$LeAdClickonline = get_option('video-LeAdClick-online');
if ($LeAdClickonline === 'on') {
wp_enqueue_script( 'video_LeAdClick_localized', plugin_dir_url( __FILE__ ) . '/js/leadclick.js', array( 'jquery' ) );
}
所以我需要的是在加载页面时禁用此代码的函数20秒谢谢
答案 0 :(得分:1)
使用$(document).ready()和setTimeout()
的组合这是一个例子
$(document).ready (function () {
//start timeout to wait for 20 second (20000 milliseconds) before executing delayed_function()
setTimeout (delayed_function, 20000)
});
//this function will get executed after 20 seconds
function delayed_function () {
alert ('20 seconds had passed after the document was ready');
}
答案 1 :(得分:-2)
您可以执行以下操作 - 因为您已经要求使用JavaScript解决方案。
document.addEventListener("DOMContentLoaded", function(){
// Handler when the DOM is fully loaded
setTimeout(function(){
//your code to be delayed by 20 sec
alert("Hello"); // for testing
}, 2000);
});