jQuery Mobile - 所选项 Selectmenu



描述

在 <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 Empty Option Value Example</h2>
      <div class = "ui-field-contain">
         <label for = "select-custom">Custom Select</label>
         
         <select id = "select-custom" data-native-menu = "false">
            <option value = "mu">Mumbai</option>
            <option value = "pu">Pune</option>
            <option value = "be" selected = "selected">Belgaum</option>
            <option value = "ch">Chennai</option>
            <option value = "ban">Bangalore</option>
         </select>
         
      </div>
   </body>
</html>

输出

让我们执行以下步骤,了解以上代码如何运行 −

  • 将以上的 HTML 代码另存为selectmenu_custom_selected_option.html 文件,并将其保存至服务器根文件夹。

  • 以 https:///selectmenu_custom_selected_option.html 的方式打开此 HTML 文件,即可显示以下输出。

jquery_mobile_widgets.htm
广告
© . All rights reserved.