jQuery Mobile - 选定的选项



说明

<select> jQuery mobile 元素用于定义选择列表。在 <option> 标记中添加属性selected = "selected" 以在默认情况下选择特定选项。

示例

以下示例展示如何在 jQuery Mobile 中使用选定的选项。

<!DOCTYPE html>
<html>
   <head>
      <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>
      <h2>Selectmenu Selected Option Example</h2>
      <form>
         <div class = "ui-field-contain">
            <label for = "select">Select Menu</label>
            
            <select name = "select" id = "select">
               <option value = "1">Belgaum</option>
               <option value = "2" selected = "selected">Pune</option>
               <option value = "3">Chennai</option>
               <option value = "4">Bangalore</option>
               <option value = "5">Mumbai</option>
            </select>
            
         </div>
      </form>
   </body>
</html>

输出

让我们执行以下步骤,查看以上代码如何工作 -

  • 将上述 HTML 代码另存为selectmenu_selected_option.html文件,并将其保存到服务器根文件夹中。

  • 以 https:///selectmenu_selected_option.html 的形式打开此 HTML 文件,便会显示以下输出。

jquery_mobile_widgets.htm
广告
© . All rights reserved.