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


jQWidgets jqxValidator validateInput()用法及代碼示例


jQWidgets 是一個 JavaScript 框架,用於為 PC 和移動設備製作基於 Web 的應用程序。它是一個非常強大、優化、獨立於平台且得到廣泛支持的框架。 jqxValidator 用於在 JavaScript 的幫助下驗證 HTML 表單。它根據用戶輸入驗證的要求,有一組內置規則,e-mail、SSN、ZIP、最大值、最小值、間隔等。自定義規則也可以根據具體情況編寫要求。

validateInput() 方法用於驗證指定 jqxValidator 的單個特定輸入。

用法:

$('#jqxValidator').jqxValidator('validateInput', 'Input');

參數:此方法接受如下所示的參數。

  • Input:這是正在執行驗證的特定輸入。

返回值:該方法不返回任何值。

鏈接文件:下載jQWidgets從給定的鏈接。在 HTML 文件中,找到下載文件夾中的腳本文件。

<link rel=”stylesheet” href=”jqwidgets/styles/jqx.base.css” type=”text/css” />
<script type=”text/javascript” src=”scripts/jquery.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxcore.js”></script>
<script type=”text/javascript” src=”jqwidgets/jqxvalidator.js”></script>

例子:下麵的例子說明了 jQWidgetsvalidateInput()方法。在下麵的示例中,僅驗證了“Designation”輸入。

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.js"> 
    </script> 
    <script type="text/javascript" 
            src="jqwidgets/jqxcore.js"> 
    </script> 
    <script type="text/javascript" 
            src="jqwidgets/jqx-all.js"> 
    </script> 
    <script type="text/javascript" 
            src="jqwidgets/jqxvalidator.js"> 
    </script> 
</head> 
  
<body> 
    <center> 
        <h1 style="color:green;"> 
            GeeksforGeeks 
        </h1> 
        <h3> 
            jQWidgets jqxValidator validateInput() Method 
        </h3> 
        <form id="Employee_Form"> 
            <table> 
                <tr> 
                    <td>Employee_Name:</td> 
                    <td> 
                        <input type="text" id="Employee_Name"/> 
                    </td> 
                </tr> 
                <tr> 
                    <td>Employee_Id:</td> 
                    <td> 
                        <input type="text" id="Employee_Id"/> 
                    </td> 
                </tr> 
                <tr> 
                    <td>Designation:</td> 
                    <td> 
                        <input type="text" id="Designation"/> 
                    </td> 
                </tr> 
                <tr> 
                    <td>Base_Location:</td> 
                    <td> 
                        <input type="text" id="Base_Location"/> 
                    </td> 
                </tr> 
            </table> 
        </form> 
        <input type="button" style="margin:28px;" 
               id="button_for_validateInput"
               value="Validate the 'Designation' Input"/> 
        
        <script type="text/javascript"> 
            
            $(document).ready(function () { 
                $('#Employee_Form').jqxValidator({ 
                    Rules: [ 
                        { 
                            input: '#Employee_Name', 
                            message: 'Employee name is mandatory!', 
                            rule: 'required' 
                        }, 
                        { 
                            input: '#Employee_Id', 
                            message: 'Employee_Id is mandatory!', 
                            rule: 'required' 
                        }, 
                        { 
                            input: '#Designation', 
                            message: 'Designation is mandatory!', 
                            rule: 'required' 
                        }, 
                        { 
                            input: '#Base_Location', 
                            message: 'base location is mandatory!', 
                            rule: 'required' 
                        }], 
                }); 
                
                $("#button_for_validateInput").jqxButton({ 
                    width: 250 
                }); 
                $("#button_for_validateInput").click( 
                    function () { 
                        $('#Employee_Form').jqxValidator( 
                            'validateInput', '#Designation'); 
                    }); 
            }); 
        </script> 
    </center> 
</body> 
</html>

輸出:

參考: https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxvalidator/jquery-validator-api.htm?search=



相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 jQWidgets jqxValidator validateInput() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。