jQWidgets jqxDropDownList loadFromSelect()方法

jQWidgets jqxDropDownList loadFromSelect()方法

jQWidgets是一个JavaScript框架,用于为PC和移动设备制作基于Web的应用程序。它是一个非常强大的、优化的、与平台无关的、被广泛支持的框架。jqxDropDownList部件是一个jQuery下拉列表,它包含了一个显示在下拉列表中的可选择项目的列表。

loadFromSelect()方法用于从一个’select’标签中加载列表项。它接受一个字符串类型的单一参数id,并且不返回任何值。

语法:

$("Selector").jqxDropDownList('loadFromSelect', 'select');

链接的文件:从链接https://www.jqwidgets.com/download/,下载jQWidgets。在HTML文件中,找到下载文件夹中的脚本文件。

<link rel=”stylesheet” href=”jqwidgets/styles/jqx.base.css” type=”text/css” />
<link rel=”stylesheet” href=”jqwidgets/styles/jqx.energyblue.css”>
<script type=”text/javascript” src=”scripts/jquery-1.11.1.min.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqx-all.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxcore.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxbuttons.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxscrollbar.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxlistbox.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxdropdownlist.js”></script>

下面的例子说明了jqxDropDownList在jQWidgets中loadFromSelect()方法。

示例:

<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet" href=
        "jqwidgets/styles/jqx.base.css" type="text/css" />
    <link rel="stylesheet" href=
        "jqwidgets/styles/jqx.energyblue.css">
    <script type="text/javascript" 
        src="scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" 
        src="jqwidgets/jqx-all.js"></script>
    <script type="text/javascript" 
        src="jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" 
        src="jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" 
        src="jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" 
        src="jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" 
        src="jqwidgets/jqxdropdownlist.js"></script>
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h3>
            jQWidgets jqxDropDownList loadFromSelect() Method
        </h3>
  
        <div id='jqxDDL'></div>
  
        <select id="select">
            <option>Computer Science</option>
            <option>C Programming</option>
            <option>C++ Programming</option>
            <option>Java Programming</option>
            <option>Python Programming</option>
            <option>HTML</option>
            <option>CSS</option>
            <option>JavaScript</option>
            <option>jQuery</option>
            <option>PHP</option>
            <option>Bootstrap</option>
        </select>
  
        <input id="jqxBtn" type="button" 
            value="Load From Select" 
            style="padding: 5px 15px; margin-top: 50px;">
    </center>
  
    <script type="text/javascript">
        (document).ready(function() {
            ("#jqxDDL").jqxDropDownList({
                theme: 'energyblue',
                width: '200px',
                height: '25px',
                selectedIndex: 2
            });
  
            var flag = false;
  
            ("#jqxBtn").click(function() {
                ("#jqxDDL").jqxDropDownList('loadFromSelect', 'select');
            });
  
            ("#jqxDDL").on('select', function(event) {
                if (event.args && !updating) {
                    ("#select").val(event.args.item.value);
                }
            });
              
            ("#select").on('change', function(event) {
                updating = true;
                var index =("#select")[0].selectedIndex;
                ("#jqxDDL").jqxDropDownList('selectIndex', index);
                ("#jqxDDL").jqxDropDownList('ensureVisible', index);
                updating = false;
            });
        });
    </script>
</body>
  
</html

输出:

jQWidgets jqxDropDownList loadFromSelect()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程