jQuery(mobile)不会触发Phonegap应用程序上的.change事件 [英] jQuery (mobile) not triggering .change event on Phonegap app

查看:111
本文介绍了jQuery(mobile)不会触发Phonegap应用程序上的.change事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(因为2天我对此没有任何问题...)

(because 2 days I had no issues with this...)

我有一个多页面布局,在我的一个页面中,我有这样的结构:

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>

在关闭body标记之前,使用以下脚本(按此顺序):

With the following scripts (in this order) before I close the body tag:

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

我的 home_m_scripts.js 文件:

$("#auto_renew").change(function(){
    alert("Changed!");
});

我的更改事件未触发,但我在这里。

My change event is not triggering though, I'm at loss here.

推荐答案

更改您的代码:

$("#auto_renew").change(function(){
    alert("Changed!");
});

To:

$(document).on('change','#auto_renew',function(){ 
    alert("Changed!"); 
});

当绑定类似这样的事件时,它将作为一个事件委托。基本上,在执行此绑定时,对象不需要存在于DOM中。

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.

这篇关于jQuery(mobile)不会触发Phonegap应用程序上的.change事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆