我需要首先触发窗口事件,点击#myDiv,有办法吗?
(function ($, w, d) {
$(d).ready(function () {
$(w).click(function() {
alert('window has been clicked');
});
$('#myDiv').click(function () {
alert('myDiv has been clicked');
});
});
})(jQuery, window, document);
答案 0 :(得分:0)
您可以将匿名#myDiv
函数包装在setTimout
调用集中0秒,这将延迟其在事件循环中的执行。
(function ($, w, d) {
$(d).ready(function () {
$(w).click(function() {
alert('window has been clicked');
});
$('#myDiv').click(function(){
setTimeout(function () {
alert('myDiv has been clicked');
}, 0);
});
});
})(jQuery, window, document);