簡體   English   中英

jQuery Mobile對話框立即關閉

[英]jQuery Mobile dialog closes immediately

我知道這個主題是眾所周知的,但是我發現的所有解決方案都不能解決我的問題。 我試圖為此創建一個小提琴,但似乎我沒有正確設置它的專門知識: http : //jsfiddle.net/tMKD3/6/ 我簡化了代碼,以更簡化地演示問題。

所以我在這里描述它,希望它是可以理解的。 我有一個jQuery Mobile頁面和一個對話框。 使用onMouseUp事件,應調用javascript函數,該函數將執行某些操作並打開對話框。 對話框應保持打開狀態,直到單擊關閉按鈕,然后再次顯示開始頁面。 就我而言,該對話框立即關閉。

這里的HTML代碼:

<body>
<div data-role="page" id="start" data-theme="e">
    <div data-role="header" data-position="fixed" data-theme="e">
         <h1 id="startHeader"></h1>

    </div>
    <div data-role="content">   
        <a href="#page" id="buttonP1" onMouseUp="setup()" data-iconpos="right" data-role="button" data-prefetch data-mini="true"></a>
        <a href="#page" id="buttonP2" onMouseUp="setup()" data-iconpos="right" data-role="button" data-prefetch data-mini="true"></a>
        <a href="#page" id="buttonP3" onMouseUp="setup()" data-iconpos="right" data-role="button" data-prefetch data-mini="true"></a>
    </div>
</div>
<!-- Dialog -->
<div data-role="dialog" id="dialog" data-theme="e">
    <div data-role="header" data-theme="e" data-position="fixed" data-close-btn="none">
         <h3 id="dialogHeader"></h3>
    </div>
    <div data-role="content" data-theme="e">
        <a href="#start" type="button" data-role="button" id="dialogButton" data-rel="back"></a>
    </div>
</div>

這是javascript代碼:

$(document).ready(function(){

    // set button text
    $("buttonP1").text("Test");
    $("buttonP2").text("Test");
    $("buttonP3").text("Test");

});

function setup() {

    // set dialog header text
    $("dialogHeader").text("Dialog");
    $("dialogButton").text("Close");

    // call dialog and the dialog should stay opened until the close button is pressed 
    $.mobile.changePage('#dialog', {
        transition: 'pop',
        role: 'dialog'
    });
    return false;

    // after calling the dialog I do some additional stuff like reset some counters and so on
}

在類似的文章中,我發現問題在於被遺忘的return false; ,但這沒有幫助。 有人知道我做錯了什么,錯誤在哪里?

預先非常感謝您的幫助。

托馬斯,問候

您可以為此設置超時:

 <script>

 $(document).ready(function(){

// set button text
$("#buttonP1").text("Test");
$("#buttonP2").text("Test");
$("#buttonP3").text("Test");

});

 function setup() {

// set dialog header text
   $("#dialogHeader").html("Dialog");
  $('#dialogButton').html('Close');

    // call dialog and the dialog should stay opened until the close button is pressed 
    setTimeout(function () {
     $.mobile.changePage('#dialog', {
     transition: 'pop',
      role: 'dialog'
   });
  }, 100);
    return false;

    // after calling the dialog I do some additional stuff like reset some counters and    so on
 }
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM