當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。