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

标签 javascript jquery

有 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/

相关文章:

javascript - 隐藏文本的复选框值组

javascript - 我可以像任何其他库一样将 JointJS 作为 AngularJS 模块注入(inject)吗?

javascript - 为什么我的输入永远不会被隐藏?

javascript - setInterval启动我的页面在生成30+数据时就卡顿了

javascript - 如何一次只打开 1 个弹出窗口?

javascript - 为什么我的 javascript 文件没有重新设置 div 的属性?

javascript - 纯 JavaScript 在没有表单的情况下发送 POST 数据

javascript - 删除 H1 之前的休息时间

php - 如何在上传前在表单中放置一个 "inline image"?

jquery - 如何在 Struts2 应用程序中对 AJAX 请求进行 CSRF 保护