2013-05-16 68 views
1

您好我有以下頁面jQuery Mobile的對話框不會永遠不會顯示

<div data-role="page" id="blockedusers"> 

     <?php 
     include 'homeheader.php'; 
     ?> 

     <div data-role="header"> 
      <a href="#" id="logoutbutton" data-role="button" data-icon="home">Log Uit</a> 
      <h1>Blocklijst</h1> 
     </div><!-- /header --> 

     <div data-role="content"> 
      <div class="grid_outer" id="grid_outer_blocklist" style="width: 295px; margin-left: auto; margin-right: auto;"> 
       <div class="grid_inner" id="grid_inner_blocklist"> 
        <h2 class="h2_header">Geblokkeerde gebruikers</h2> 
        <?php 
        show_blocked_users($blockedusers); 
        ?> 
       </div> 
      </div> 
     </div> 
     <div data-role="navbar"> 
      <ul> 
       <li> 
        <a href="#" data-rel="back" data-icon="back">terug</a> 
       </li> 
      </ul> 
     </div><!-- /navbar --> 
     <div data-role="footer"> 
      <h4>Blocklijst</h4> 
     </div> 
    </div><!-- /content --> 
    <div data-role="dialog" id="confirmbox"> 
     <div data-role="header" data-icon="false"> 
      <h1>Bevestig</h1> 
     </div><!-- /header --> 

     <div data-role="content"> 
      <h3 id="confirmMsg">Bevestig</h3> 

      <br> 

      <center> 
       <a href="#" class="btnConfirmYes" data-role="button" data-icon="check" data-mini="true" data-inline="true">&nbsp;&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp; </a> 
       &nbsp;&nbsp;&nbsp; 
       <a href="#" class="btnConfirmNo" data-role="button" data-rel="back" data-icon="delete" data-mini="true" data-inline="true">No</a> 
      </center> 
     </div> 
    </div> 

而且我在外部JS以下JavaScript文件

$(document).on('pagebeforeshow', '#blockedusers', function() { 

alert('pagebeforeshow blockedusers'); 

$('[id=unblocklink]').click(function(e) { 

    e.preventDefault(); 
    var userid = $(this).attr('userid'); 

    alert('unblocklink clicked userid ' + userid); 

    showConfirm("Weet je zeker dat je deze gebruiker wilt deblokkeren?", function() { 

     $.ajax({ 
      async : false, 
      url : "../php/process_unblock_user.php?userid=" + userid, 
      success : function(data) { 
       if (data != "") { 
        // in case of error 
        alert(data); 
       } else { 
        alert("Gebruiker gedeblokkeerd!"); 
        window.location.reload(true); 

       } 
      } 
     }); 
    }); 

}); 

// confirm dialog 
function showConfirm(msg, callback) { 

    alert('showing dialog1'); 

    $("#confirmMsg").text(msg); 
    $("#confirmbox .btnConfirmYes").on("click.confirmbox", function() { 
     $("#confirmbox").dialog("close"); 
     callback(); 
    }); 

    $("#confirmbox .btnConfirmNo").off("click.confirmbox", function(r) { 
    }); 

    alert('showing dialog2'); 

    $.mobile.changePage('#confirmbox', { 
     allowSamePageTransition : true 
    }); 

} 

}); 

的問題是,在confirmdialog顯示(? ??)。我在同一頁面上添加了javascript,但是我遇到了unblocklink問題。

+0

如果你在沒有代碼之前只使用'$ .mobile.changePage('#confirmbox')'調用它,它是否工作? – Omar

+0

@omar,當我點擊取消阻止鏈接後,我不再刷新頁面。 –

回答

0

好,我找到了一個解決方案來解決該問題:

當導航到從主頁的blockedusers頁,我需要做的是通過以下方式:

$('#blockedusers').click(function(e) { 
window.location.href = "blockedusers.php"; 
}); 

才把confirmbox是在DOM中可用。

這不起作用:

$.mobile.changePage('blockedusers.php'); 

希望這個解決方案能夠幫助更多的人出來。