jQuery Mobile: formulario en la barra de herramientas

Descripción

El formulario se puede utilizar en barras de herramientas. Se puede colocar en encabezados y pies de página usando su <form> normal .

Ejemplo

El siguiente ejemplo demuestra el uso del formulario en la barra de herramientas en jQuery Mobile.

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>
      
   <body>
      <div data-role = "page" class = "jqm-demos">
         <div data-role = "header" data-position = "fixed">
            <a href = "#" data-rel = "back" class = "ui-btn ui-btn-left ui-alt-icon 
               ui-nodisc-icon ui-corner-all ui-btn-icon-notext ui-icon-carat-l">Back</a>
            <h2>Header</h2>
            <form method = "post" action = "#">
               <fieldset data-role = "controlgroup" data-type = "horizontal">
                  <legend>Choose your colors:</legend>
                  <label for = "red">Red</label>
                  <input type = "checkbox" name = "favcolor" id = "red" value = "red">
                  <label for = "green">Green</label>
                  <input type = "checkbox" name = "favcolor" id = "green" value = "green">
                  <label for = "blue">Blue</label>
                  <input type = "checkbox" name = "favcolor" id = "blue" value = "blue">
               </fieldset>
            </form>
         </div>
         
         <div class = "ui-content" role = "main">
            <ul data-role = "listview" data-split-icon = "gear" data-theme = "a" 
               data-dividertheme = "e" data-filter = "true" data-filter-theme = "a" 
               data-filter-placeholder = "Search Your Item...">
               <li><a href = "#">
                  <h2>Tshirts</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            
               <li><a href = "#">
                  <h2>Formal Shirts</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            
               <li><a href = "#">
                  <h2>Trousers</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            
               <li><a href = "#">
                  <h2>Suits & Blazers</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            
               <li><a href = "#">
                  <h2>Sneakers</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            
               <li><a href = "#">
                  <h2>Casual Shoes</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            
               <li><a href = "#">
                  <h2>Backpacks</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            
               <li><a href = "#">
                  <h2>Perfumes</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            
               <li><a href = "#">
                  <h2>Jeans</h2></a>
                  <a href = "#purchase" data-rel = "popup" data-position-to = "window" 
                     data-transition = "pop">Purchase Item</a>
               </li>
            </ul>

            <div data-role = "popup" id = "purchase" data-overlay-theme = "b" 
               class = "ui-content" style = "max-width:340px; padding-bottom:2em;">
               <h2>Purchase Item?</h2>
               <p>In order to purchase this item click Buy or Cancel.</p>
               <a href = "#" class = "ui-btn ui-btn-b ui-btn-inline ui-mini ui-corner-all 
                  ui-shadow ui-btn-icon-left ui-icon-check" data-rel = "back">Buy: $25</a>
               <a href = "#" class = "ui-btn ui-btn-inline ui-mini ui-corner-all ui-shadow" 
                  data-rel = "back">Cancel</a>
            </div>
         </div>
         
         <div data-role = "footer" data-theme = "a" data-position = "fixed">
            <h2>Footer</h2>
            <div class = "ui-bar ui-bar-a">
               <form action = "#" method = "get">
                  <input type = "text" name = "name" id = "name" data-mini = "true" 
                     placeholder = "Name" />
                  <input type = "email" name = "email" id = "email" 
                     placeholder = "Your email" data-mini = "true">
                  <textarea name = "addinfo" id = "info" data-mini = "true" 
                     placeholder = "Comments"></textarea>
                  <button type = "submit" class = "ui-btn ui-btn-a ui-corner-all ui-mini">
                     Submit</button>
               </form>
            </div>
         </div>
      </div>
   </body>
</html>

Salida

Realicemos los siguientes pasos para ver cómo funciona el código anterior:

  • Guarde el código html anterior como toolbar_form.html archivo en la carpeta raíz de su servidor.

  • Abra este archivo HTML como http: //localhost/toolbar_form.html y se mostrará el siguiente resultado.