当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


jQWidgets jqxComboBox val()用法及代码示例


jQWidgets 是一个 JavaScript 框架,用于为 PC 和移动设备制作基于 Web 的应用程序。它是一个非常强大和优化的框架,独立于平台,并得到广泛支持。 jqxComboBox 用于表示 jQuery Combobox 小部件,该小部件包含具有自动完成函数的输入字段和显示在下拉列表中的可选项目列表。

val() 方法用于设置或返回选定的值。它接受可选的字符串类型的单个参数值,并返回字符串类型的值。

用法:

// Get the value
var value = $('selector').jqxComboBox('val');   or
var value = $('selector').val();

// Set the value
$('selector').jqxComboBox('val', 'New Value');  or
$('selector').val('New Value');


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

<link rel=”stylesheet” href=”jqwidgets/styles/jqx.base.css” type=”text/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/jqxcolorpicker.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/jqxcombobox.js”></script>

下面的例子说明了 jQWidgets 中的 jqxComboBox val() 方法:

例:

HTML


<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet" href=
"jqwidgets/styles/jqx.base.css" 
          type="text/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/jqxcolorpicker.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/jqxcombobox.js">
    </script>
</head>
  
<body>
    <center>
        <h1 style="color:green;">
            GeeksforGeeks
        </h1>
  
        <h3>
            jQWidgets jqxComboBox val() Method
        </h3>
  
        <div id='jqxCB'></div>
        <br>
        <input type="button" id='jqxBtn' 
            style="padding:5px 20px;" 
            value="Set Value" />
    </center>
  
    <script type="text/javascript">
        $(document).ready(function() {
            var data = [
                "Computer Science",
                "C Programming",
                "C++ Programming",
                "Java Programming",
                "Python Programming",
                "HTML",
                "CSS",
                "JavaScript",
                "jQuery",
                "PHP",
                "Bootstrap"
            ];
  
            $("#jqxCB").jqxComboBox({
                source:data,
                width:'250px',
                animationType:'slide',
                selectedIndex:0
            });
  
            $("#jqxCB").jqxComboBox('checkAll');
  
            $('#jqxBtn').on('click', function() {
                var index = $("#jqxCB").jqxComboBox(
                    'val', 'Python Programming');
            });
        });
    </script>
</body>
  
</html>

输出:

参考: https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxcombobox/jquery-combobox-api.htm




相关用法


注:本文由纯净天空筛选整理自ppatelkap大神的英文原创作品 jQWidgets jqxComboBox val() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。