事件加载并准备不触发 [英] events load and ready not firing
问题描述
这是我的代码:
$(document).on('ready load click',function(){
console.log('hiihuhu')
})
我包括了上面的jquery脚本. 问题在于click事件正在触发,但load或ready事件却没有. 我的控制台没有看到任何错误. 可能是什么问题?
I included the jquery script above. The problem is the click event is firing but the load or ready event is not. I don't see any error in my console. What could be the problem?
推荐答案
您正在使用哪个版本的jQuery
Which Version of jQuery are you using
根据jQuery文档
$(document).on("ready",handler),从jQuery 1.8开始弃用,并在jQuery 3.0中删除.请注意,如果在附加此事件之前DOM准备就绪,则将不执行处理程序.
$( window ).load(function() {
alert("hello");
});
$(document).ready(function(){
$(document).on('click',function(){
alert("in click event");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>hello</div>
-
窗口加载::当所有内容(包括图像)均已加载时被触发
Window onload: :Is fired when all the content including images has been loaded
document.ready :加载html文档后被触发
document.ready : Is fired after html document is loaded
所以我想您无法将所有三个事件都准备就绪,加载并单击尝试的方式
So i guess you cannot combine all three events ready,load and click the way you have tried
希望有帮助
这篇关于事件加载并准备不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!