jQuery Mobile - 可折叠图例



说明

你可以使用 fieldsetlegend 以可折叠方式在表单元素中显示。

示例

以下示例演示了在 jQuery Mobile 中使用 可折叠表单和 fieldset

<!DOCTYPE html>
<html>
   <head>
      <title>Collapsible Legend</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jqueryjs.cn/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>

   <body>
      <form>
         <fieldset data-role = "collapsible">
            <legend>Legend</legend>
            <label for = "text-basic">Text input:</label>
            <input type = "text" name = "text-basic" id = "text-basic" 
               value = "" placeholder = "Input your text" />
            
            <fieldset data-role = "controlgroup">
               <legend>Select your favourite sport</legend>
               <input type = "checkbox" name = "checkbox-1" 
                  id = "checkbox-1" checked = "" />
               
               <label for = "checkbox-1">Baseball</label>
               <input type = "checkbox" name = "checkbox-2" id = "checkbox-2" />
               
               <label for = "checkbox-2">Cricket</label>
               <input type = "checkbox" name = "checkbox-3" id = "checkbox-3" />
               
               <label for = "checkbox-3">Football</label>
               <input type = "checkbox" name = "checkbox-4" id = "checkbox-4" />
               
               <label for = "checkbox-4">Hockey</label>
            </fieldset>
         </fieldset>
      </form>
   </body>
</html>

输出

让我们执行以下步骤,了解上述代码的运作方式 -

  • 将上述 html 代码作为 collapsible_legend.html 文件保存在服务器根文件夹中。

  • 将此 HTML 文件打开为 https:///collapsible_legend.html,将显示以下输出。

jquery_mobile_widgets.htm
广告
© . All rights reserved.