最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery mobile panel events not firing - Stack Overflow

programmeradmin0浏览0评论

I can't seem to tie into the jquery mobile panel events as seen here

.3.0-rc.1/docs/panels/events.html

$(document).on('beforeopen', ".ui-panel", function() {
    alert('open');
});
$(document).on('beforeclose', ".ui-panel", function() {
    alert('close');
 });

or

 $(document).on('open', ".ui-panel", function() {
    alert('open');
});
$(document).on('close', ".ui-panel", function() {
    alert('close');
 });

or even using context on the panel

$('.ui-panel',context).on('open', function() {
    alert('opened');
});

where context is a jquery object variable of the current page

I can't seem to tie into the jquery mobile panel events as seen here

http://jquerymobile./demos/1.3.0-rc.1/docs/panels/events.html

$(document).on('beforeopen', ".ui-panel", function() {
    alert('open');
});
$(document).on('beforeclose', ".ui-panel", function() {
    alert('close');
 });

or

 $(document).on('open', ".ui-panel", function() {
    alert('open');
});
$(document).on('close', ".ui-panel", function() {
    alert('close');
 });

or even using context on the panel

$('.ui-panel',context).on('open', function() {
    alert('opened');
});

where context is a jquery object variable of the current page

Share asked May 24, 2013 at 1:51 BrianBrian 4,41814 gold badges63 silver badges105 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

Taking a look at the jQuery mobile API

It provides examples for beforeopen(event, ui) which is a type of panelbeforeopen, they provide these examples in the API documentation:

1) Initialize the panel with the beforeopen callback specified:

$( ".selector" ).panel({
  beforeopen: function( event, ui ) {}
});

2) Bind an event listener to the panelbeforeopen event:

$( ".selector" ).on( "panelbeforeopen", function( event, ui ) {} );

you must insert your code inside $( document ).on( "pageinit", function( event, data ){.....

   $(document).on( "pageinit", function( event, data ){
     $( ".ui-panel" ).on( "panelbeforeclose", function( event, ui ) {
        // your code here
     } );
   });

You have to reference the correct div for it to work. Your selector needs to reference the div that has data-role="panel".

$(window).on("load",function(){

    $( "#your-panel-id" ).on( "panelclose", function( event, ui ) {
        alert ('hi') ;
    }); 
}); 
发布评论

评论列表(0)

  1. 暂无评论