如何从jquery移动动态页面中的按钮获取事件 [英] How to get an event from button in jquery mobile dynamic page

查看:57
本文介绍了如何从jquery移动动态页面中的按钮获取事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jquery mobile创建了一个动态页面,如何在创建此页面后获取事件?此外,我需要从此按钮发出提醒。

I have created a dynamic page using jquery mobile, how to get an event after creating this page? Also i need an alert from this button.

这是我的代码:

 $("#test").on('click',function(){
    var newPage = $("<div data-role=page data-url=testpage><div data-role=header>        <h1>TEST</h1></div><div data-role=content> <input type='button' value='clic kMe' id='click_me'> </div></div>");
    newPage.appendTo( $.mobile.pageContainer );
    $.mobile.changePage( newPage );
 });


推荐答案

使用此:

    $(document).on('click','#click_me',function() {
        alert('Click');
    });  

或代码:

$("#test").on('click',function(){
    var newPage = $("<div data-role=page data-url=testpage><div data-role=header><h1>TEST</h1></div><div data-role=content> <input type='button' value='clic kMe' id='click_me'> </div></div>");
    $(document).on('click','#click_me',function() {
        alert('Click');
    }); 
    newPage.appendTo( $.mobile.pageContainer );
    $.mobile.changePage( newPage );
});

这篇关于如何从jquery移动动态页面中的按钮获取事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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