2012-12-04 58 views
0

我想運行一個自創的函數,然後當真正運行jQuery Mobile PopUp,但不知道如何?運行函數,然後用jQuery Mobile激活函數?

這是我覺得我應該做的:

$(document).ready(function() { 
    var finished = false; 
    $("#mytest").click(function() { 
     // RUN MY FUNCTION AND THE IF TRUE RUN POPUP 
     if(finished == true){ 
     // ACTIVATE JQUERY MOBILE POPUP FUNCTION 
     } 
    }); 
}); 

我那麼應該激活mytest的功能是這樣的:

<a style="height: 75px;" href="" data-rel="popup" data-role="button" id="mytest">Test</a> 

似乎沒有任何雖然發生?我似乎沒有進入mytest功能?當我進入時,如何激活彈出功能?

希望能幫忙:-)

回答

0

看到工作示例:finished == truefinished == false:按一下按鈕,看看會發生什麼...
1)finished == true:彈出自動
2)finished == false打開:我用return false防止打開彈出

腳本:

$(document).bind('pageinit', function() { 
     $("#mytest").click(function() { 
     var finished = false; 
     // RUN MY FUNCTION AND THEN IF TRUE RUN POPUP (WILL OPEN AUTOMATICALLY) 
     if(finished == false){ 
      // PREVENT OPENING POPUP 
      return false; 
     } 
     }); 
    }); 

完整的例子:

<html> 
<head> 
    <meta charset="utf-8"> 
    <title>popup</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 
</head> 

<body> 
    <div data-role="page" id="myPage"> 
    <div data-role="content"> 
     <h1>Popup</h1> 
     <a style="height: 75px;" href="#eat" data-rel="popup" data-role="button" id="mytest">Test</a> 
    </div> 

    <section data-role="popup" data-overlay-theme="a" id="eat"> 
     Are you sure you want to eat? 
    </section> 

    <script> 
    $(document).bind('pageinit', function() { 
     $("#mytest").click(function() { 
     var finished = false; 
     // RUN MY FUNCTION AND THEN IF TRUE RUN POPUP (WILL OPEN AUTOMATICALLY) 
     if(finished == false){ 
      // PREVENT OPENING POPUP 
      return false; 
     } 
     }); 
    }); 
    </script> 
    </div> 

</body> 
</html> 
+0

嗨,泰夫,謝謝,但我不能得到任何彈出? – Mansa

+0

查看已更新的答案... – Taifun

0

試試這個!

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>popup</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 

     <script> 
     $().ready(function() { 
      $(document).bind('pageinit', function() { 
       $("#mytest").click(function() { 
        var finished = false; 
        // RUN MY FUNCTION AND THEN IF TRUE RUN POPUP (WILL OPEN AUTOMATICALLY) 
        if (finished == false) { 
         // PREVENT OPENING POPUP 
         return false; 
        } 
       }); 
      }); 

     }); 
    </script> 
</head> 

<body> 
    <div data-role="page" id="myPage"> 
    <div data-role="content"> 
     <h1>Popup</h1> 
     <a style="height: 75px;" href="#eat" data-rel="popup" data-role="button" id="mytest">Test</a> 
    </div> 



    <div data-role="popup" id="eat" data-theme="c" data-overlay-theme="c"> 
    Eat Something 
    </div> 


    </div> 

</body> 
</html>