我正在研究一个jQuery的移动应用程序,并且遇到将on-change事件绑定到文件输入元素的问题。第一次访问page1.php时,事件正确启动。但是,在访问另一个jQuery网站(page2.php)并返回到page1.php后,事件不会触发(因为我使用chrome的检查工具进行调试,事件甚至没有在第二次访问page1-php时发生) 。当回到页面时,jquery移动事件没有被绑定
我也曾经尝试过不同的页面事件作为http://www.gajotres.net/page-events-order-in-jquery-mobile 和http://www.gajotres.net/prevent-jquery-multiple-event-triggering/
这里描述的结合事件是page1.php中的代码:
$(document).on('pagebeforeshow', '#serialSelect', function(){
$("#qrImageSelect").off('change', '#qrImageFile').on('change','#qrImageFile' , function(){
var selectedFiles = $('#qrImageFile')[0].files;
serialNumber = readSerialNumber(selectedFiles);
window.location.href = "page2.php?sn="+serialNumber;
});
});
<link href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" rel="stylesheet"/>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<form id="qrImageSelect" class="ui-btn ui-body ui-body-a ui-corner-all ui-icon-plus ui-btn-icon-left fileinput-button" accept-charset="UTF-8">
<span>QR code</span>
<input type="file" name="qrImageFile" data-role="none" id="qrImageFile" />
</form>
page2.php(相同的jQuery版本)
<a href="page1.php" data-role="button" class="serial-model-button">
回来时,第1页为什么不绑定的事件? 我希望得到任何帮助:)
编辑: 一些背景资料:我想加载的QR码的图片。 QR码包含一个serialNumber。取决于我想加载相关页面的serialNumber。应该有可能从这个网站回来扫描一个新的QR码。 Sombody有一个想法以不同的方式解决这个问题?
在页面之间前后移动会使服务器每次都有新的“请求”,它就像从零开始,没有事件被初始化。 –
但它第一次加载页面(就像我重新加载页面1时)。但是当直接从page2返回时,它不起作用。如果它“从零开始”,它应该以与我重新加载页面时相同的方式工作? –
你想实现什么? –