請選擇汽車類型:

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

ASP.NET jQuery 食譜15 (通過控件CustomValidat

系統 2422 0

這節我們要講下如何通過控件CustomValidator來校驗CheckBoxList,客戶端校驗代碼通過jQuery實現。

首先看下界面代碼:

      
        <
      
      
        form 
      
      
        id
      
      
        ="form1"
      
      
         runat
      
      
        ="server"
      
      
        >
      
      
< div align ="center" >
< fieldset style ="width: 350px; height: 200px;" >
< table border ="0" cellpadding ="3" cellspacing ="3" >
< tr >
< td >
請選擇汽車類型:
</ td >
</ tr >
< tr >
< td >
< asp:CheckBoxList ID ="chkCar" runat ="server" >
< asp:ListItem Value ="1" Text ="奔馳汽車" ></ asp:ListItem >
< asp:ListItem Value ="2" Text ="寶馬汽車" ></ asp:ListItem >
< asp:ListItem Value ="3" Text ="奧迪汽車" ></ asp:ListItem >
< asp:ListItem Value ="4" Text ="現代汽車" ></ asp:ListItem >
< asp:ListItem Value ="5" Text ="豐田汽車" ></ asp:ListItem >
</ asp:CheckBoxList >
</ td >
</ tr >
< tr >
< td >
< asp:Button ID ="btnSubmit" runat ="server" Text ="提交" />
</ td >
</ tr >
</ table >
</ fieldset >
< asp:CustomValidator ID ="ctvCar" runat ="server" Display ="Dynamic" ErrorMessage ="至少選擇三種車!"
ForeColor
="Red" ClientValidationFunction ="ctvCar_Validation" ></ asp:CustomValidator >
</ div >
</ form >

控件CustomValidator相關參數說明:

ErrorMessage:設置校驗提示信息

Display:設置顯示模式,Dynamic表示提示信息不顯示的時候,不占用當前位置

ClientValidationFunction:設置定義客戶端自定義校驗函數

客戶端腳本代碼:

      
        <
      
      
        head 
      
      
        id
      
      
        ="Head1"
      
      
         runat
      
      
        ="server"
      
      
        >
      
      
< title > Recipe15 </ title >
< script type ="text/javascript" src ="Scripts/jquery-1.4.1-vsdoc.js" ></ script >
< script type ="text/javascript" >
function ctvCar_Validation(sender, args) {
// CustomValidator控件通過自定義函數的參數args屬性IsValid來判斷是否驗證通過
args.IsValid = ($( " #chkCar input:checked " ).length >= 3 );
}
</ script >
</ head >

最終顯示效果:

ASP.NET jQuery 食譜15 (通過控件CustomValidator驗證CheckBoxList)_第1張圖片





ASP.NET jQuery 食譜15 (通過控件CustomValidator驗證CheckBoxList)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 海林市| 通海县| 新竹市| 凤阳县| 子长县| 民乐县| 三原县| 文山县| 镇巴县| 金坛市| 融水| 南汇区| 江口县| 台中县| 和林格尔县| 资兴市| 绥德县| 清徐县| 衡南县| 固镇县| 荥经县| 北安市| 资源县| 华阴市| 滁州市| 沾益县| 眉山市| 保德县| 宜宾市| 昔阳县| 巴林右旗| 清河县| 历史| 新民市| 南靖县| 永和县| 安化县| 水城县| 利川市| 保德县| 南康市|