"$(document).on('pageshow'"不适用于jQuery 1.9.1 + JQM 1.3.0稳定 [英] "$(document).on('pageshow'" not working with jQuery 1.9.1 + JQM 1.3.0-stable
本文介绍了"$(document).on('pageshow'"不适用于jQuery 1.9.1 + JQM 1.3.0稳定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jQuery 1.8.3
Working with jQuery 1.8.3
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-1.8.3.min.js"></script>
<script src="js/jquery.mobile-1.3.0.min.js"></script>
<script>
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
$("#home").live("pageshow", function( event ) {
alert( "Ok. This is Home!" );
});
</script>
</head>
<body>
<!--- HOME --->
<div data-role="page" id="home">
<h2>Hello World</h2>
</div>
</body>
</html>
警报正常.
但是,使用jQuery 1.9.1(请注意,我更改了版本,并使用"on"更改了"live".
However, with jQuery 1.9.1 (please note that I changed the version and "live" with "on".
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.mobile-1.3.0.min.js"></script>
<script>
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
$("#home").on("pageshow", function( event ) {
alert( "Ok. This is Home!" );
});
</script>
</head>
<body>
<!--- HOME --->
<div data-role="page" id="home">
<h2>Hello World</h2>
</div>
</body>
</html>
警报将不起作用.我确定我做错了什么.我一直在阅读稳定的jQuery Mobile 1.3.0将使用jQuery 1.9.1,但也许我错了.
Alert won't work. I'm sure I'm doing something wrong. I've been reading that jQuery Mobile 1.3.0-stable would use jQuery 1.9.1, but perhaps I'm wrong.
推荐答案
更改
$("#home").on("pageshow", function( event ) {
到
$(document).on("pageshow", "#home", function( event ) {
on
的语法与live
的语法不同:进行绑定时,用于接收和委托事件的元素必须存在.
The syntax of on
isn't the same than the one of live
: the element that will receive and delegate the event must be existing when you make the binding.
这篇关于"$(document).on('pageshow'"不适用于jQuery 1.9.1 + JQM 1.3.0稳定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文