jQuery UI选择菜单

jQuery UI选择菜单

在这篇文章中,我们将使用jQuery UI selectmenu部件建立一个选择菜单,该部件可以为我们提供选择选项。我们可以使用这个小部件来制作一个不同行动的表单。

语法:

$( ".selector" ).selectmenu();

参数:它不接受任何参数。

返回值:它从jQuery UI中返回一个选择菜单。

预编译的文件:请下载库,然后使用下面给出的脚本的路径。

<link rel=”stylesheet” href=”//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css”>
<script src=”https://code.jquery.com/jquery-1.12.4.js”></script>
<script src=”https://code.jquery.com/ui/1.12.1/jquery-ui.js”></script>

例子:在这个例子中,我们可以看到,我们将使用jQuery UI的selectmenu widget建立一个简单的选择菜单。

<!doctype html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1">
  
    <link href=
"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/
               themes/ui-lightness/jquery-ui.css" 
               rel="stylesheet" type="text/css" />
  
    <script src="https://code.jquery.com/jquery-1.12.4.js">
    </script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js">
    </script>
  
    <script>
        (function () {
            ("#title").selectmenu();
        });
    </script>
    <style>
        .ui-menu {
            width: 150px;
        }
  
        .widget-header {
            padding: 0.2em;
            color: white;
        }
    </style>
</head>
  
<body>
    <h3>
        Geeks for Geeks Selectmenu 
        Using jQuery UI
    </h3>
      
    <div>
        <form action="#">
            <fieldset>
                <label for="title">Select a title</label>
                <select name="title" id="title">
                    <option disabled selected>
                        Please pick one</option>
                    <option>Python</option>
                    <option>Java</option>
                    <option>HTML</option>
                    <option>C++</option>
                    <option>Other</option>
                </select>
            </fieldset>
        </form>
    </div>
</body>
  
</html>

输出:

jQuery UI选择菜单

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程