[英]jQuery (mobile) not triggering .change event on Phonegap app
(because 2 days I had no issues with this...) (因为2天我对此没有任何问题......)
I have a multipage layout, in one of my pages I have a structure like so: 我有一个多页面布局,在我的一个页面中,我有一个像这样的结构:
<div id="view_offer" data-role="page">
<div data-role="header">
<h1>Edit Offer</h1>
</div>
<div data-role="content">
<p><label><input id="auto_renew" type="checkbox" name="checkbox-0">Auto renew?</label></p>
</div>
</div>
With the following scripts (in this order) before I close the body tag: 在关闭body标记之前,使用以下脚本(按此顺序):
<script src="js/cordova-2.5.0.js"></script>
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/jquery.mobile-1.3.0.min.js"></script>
<script src="js/home_m_scripts.js"></script>
My home_m_scripts.js file: 我的home_m_scripts.js文件:
$("#auto_renew").change(function(){
alert("Changed!");
});
My change event is not triggering though, I'm at loss here. 我的改变事件并没有触发,我在这里失去了。
Change your code from: 更改您的代码:
$("#auto_renew").change(function(){
alert("Changed!");
});
To: 至:
$(document).on('change','#auto_renew',function(){
alert("Changed!");
});
When you bind an event like this it will act as an event delegation. 绑定此类事件时,它将充当事件委派。 Basically object don't need to exist in a DOM when you execute this binding. 基本上,当您执行此绑定时,对象不需要存在于DOM中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.