gpt4 book ai didi

javascript - Jquery 1.5.2 替代 .on() 函数

转载 作者:行者123 更新时间:2023-12-02 15:37:32 24 4
gpt4 key购买 nike

有 Jquery 专家可以帮助我吗?

我在一个需要使用 Jquery 1.5.2 的项目中,并且需要使用 .on() 函数。

有什么方法可以让它发挥作用?

代码模型如下:

$(document).on('mozfullscreenchange webkitfullscreenchange fullscreenchange',function(){
//some code
alert("fulscreen change")
});

function fullscreen() {
alert("full");
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<button onclick='fullscreen()'>fullscreen</button>

最佳答案

您可以使用live() 旧版本

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live(). ( Taken from http://api.jquery.com/live/ )

$('button').live('click', function() {
alert('clicked');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

<button>click</button>

关于javascript - Jquery 1.5.2 替代 .on() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32824210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com