Framework7 - 在 Picker 中打开

说明

通过将 data-open-in 属性设置为 picker,智能选择可以显示为选择器模式。

示例

以下示例演示了在 Framework7 中使用智能选择在 Picker 中打开−

<!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>Open in Picker</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 = "left"> </div>
                  <div class = "center sliding">Smart Select Open in Picker</div>
                  <div class = "right"> </div>
               </div>
            </div>
            
            <div class = "pages navbar-through">
               <div data-page = "home" class = "page">
                  <div class = "page-content">
                     <div class = "list-block">
                        <ul>
                           <li>
                              <a href = "#" data-open-in = "picker" class = "item-link smart-select">
                              
                                 <select name = "countries">
                                    <option value = "India" selected>India</option>
                                    <option value = "Newz = Zealnad">New Zealand</option>
                                    <option value = "Srilanka">Srilanka</option>
                                    <option value = "WestIndies">West Indies</option>
                                    <option value = "China">China</option>
                                 </select>
                                 
                                 <div class = "item-content">
                                    <div class = "item-inner">
                                       <div class = "item-title">Countries</div>
                                    </div>
                                 </div>
                              </a>
                           </li>
                           
                           <li>
                              <a href = "#" data-open-in = "picker" data-picker-close-text = "Close the List" class = "item-link smart-select">
                              
                                 <select name = "sports">
                                    <option value = "Cricket">Cricket</option>
                                    <option value = "Hockey">Hockey</option>
                                    <option value = "Football">Football</option>
                                    <option value = "Volleyball" selected>Volleyball</option>
                                    <option value = "Rugby">Rugby</option>
                                 </select>
                                 
                                 <div class = "item-content">
                                    <div class = "item-inner">
                                       <div class = "item-title">Sports</div>
                                    </div>
                                 </div>
                              </a>
                           </li>
                        </ul>
                     </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>
         // 此处初始化应用程序
         var myApp = new Framework7 ({
            animateNavBackIcon:true
         });

         // 如果您使用自定义 DOM 库,则将其保存到 $$ 变量
         var $$ = Dom7;

         // 添加视图
         var mainView = myApp.addView('.view-main', {
         
            // 为该视图启用动态导航栏
            dynamicNavbar: true
         });
      </script>
   </body>

</html>

输出

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

  • 将上述 HTML 代码保存为服务器根文件夹中的 smart_select_picker.html 文件。

  • 将此 HTML 文件作为 http://localhost/smart_select_picker.html 打开,输出如下所示。

  • 通过将属性 data-open-in 设置为 picker,输出显示智能选择,该智能选择显示为选择器模式。

  • 当您单击任何一个选项时,它会显示为选择器模式,其中包含一个选项列表,您可以在其中选择任何一个选项。

framework7_forms.html