Framework7 - 警报模态框



描述

您可以使用以下方法显示警报模态框:

myApp.alert(text, [title, callbackOk])

或者

myApp.alert(text, [callbackOk]) 

上述方法接受参数,列示如下:

  • text − 显示带有文本的警报。

  • title − 可选方法,显示带有标题的警报。

  • callbackOk − 可选方法,提供回调函数,在用户点击警报模态框上的“确定”按钮时执行。

示例

以下示例演示了在 Framework7 中使用警报模态框的方法,点击链接时会显示警报框:

<!DOCTYPE html>
<html>

   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, 
         maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" />
      <meta name = "apple-mobile-web-app-capable" content = "yes" />
      <meta name = "apple-mobile-web-app-status-bar-style" content = "black" />
      <title>Alert Modal</title>
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />
   </head>

   <body>
      <div class = "views">
         <div class = "view view-main">
         
            <div class = "navbar">
               <div class = "navbar-inner">
                  <div class = "center sliding">Alert Modal</div>
               </div>
            </div>
            
            <div class = "pages">
               <div data-page = "index" class = "page navbar-fixed">
                  <div class = "page-content">
                     <div class = "content-block">
                        <p><a href = "#" class = "alert-text">Displays Alert Modal with Text</a></p>
                        
                        <p><a href = "#" class = "alert-text-title">Displays Alert Modal With Text and Title</a></p>
                        
                        <p><a href = "#" class = "alert-text-title-callback">Displays Alert Modal With Text and Title and Callback</a></p>
                        
                        <p><a href = "#" class = "alert-text-callback">Displays Alert Modal With Text and Callback</a></p>
                     </div>
                  </div>
               </div>
            </div>
            
         </div>
      </div>
      
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>
         
      <script>
         // Here you can initialize the app
         var myApp = new Framework7();

         // If your using custom DOM library, then save it to $$ variable
         var $$ = Dom7;

         // Add the view
         var mainView = myApp.addView('.view-main', {
         
            // enable the dynamic navbar for this view:
            dynamicNavbar: true
         });

         $$('.alert-text').on('click', function () {
            myApp.alert('This is alert text!!!');
         });

         $$('.alert-text-title').on('click', function () {
            myApp.alert('This is alert text!!!', 'My Title!');
         });

         $$('.alert-text-title-callback').on('click', function () {
            myApp.alert('This is alert text!!!', 'My Title!', function () {
               myApp.alert('You have clicked the button!!!')
            });
         });

         $$('.alert-text-callback').on('click', function () {
            myApp.alert('This is alert text!!!', function () {
               myApp.alert('You have clicked the button!!!')
            });
         });
      </script>
   </body>

</html>

输出

让我们执行以下步骤来查看上述代码的工作原理:

  • 将上述 HTML 代码保存为名为 modal_alert.html 的文件到您的服务器根目录。

  • 以 https://127.0.0.1/modal_alert.html 的方式打开此 HTML 文件,输出结果如下所示。

  • 当用户点击第一个选项时,它会显示带有文本的警报模态框。

  • 当用户点击第二个选项时,它会显示带有文本和标题的警报模态框。

  • 当用户点击第三个选项时,它会显示带有文本和标题的警报模态框,并且当点击“确定”时,它会执行回调函数。

  • 当用户点击最后一个选项时,它会显示带有文本的警报模态框,并且当点击“确定”时,它会执行回调函数。

framework7_overlays.htm
广告