ASP.NET jQuery 食譜15 (通過(guò)控件CustomValidat
系統(tǒng)
2223 0
這節(jié)我們要講下如何通過(guò)控件CustomValidator來(lái)校驗(yàn)CheckBoxList,客戶端校驗(yàn)代碼通過(guò)jQuery實(shí)現(xiàn)。
首先看下界面代碼:
<
form
id
="form1"
runat
="server"
>
<
div
align
="center"
>
<
fieldset
style
="width: 350px; height: 200px;"
>
<
table
border
="0"
cellpadding
="3"
cellspacing
="3"
>
<
tr
>
<
td
>
請(qǐng)選擇汽車類型:
</
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
="現(xiàn)代汽車"
></
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相關(guān)參數(shù)說(shuō)明:
ErrorMessage:設(shè)置校驗(yàn)提示信息
Display:設(shè)置顯示模式,Dynamic表示提示信息不顯示的時(shí)候,不占用當(dāng)前位置
ClientValidationFunction:設(shè)置定義客戶端自定義校驗(yàn)函數(shù)
客戶端腳本代碼:
<
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控件通過(guò)自定義函數(shù)的參數(shù)args屬性IsValid來(lái)判斷是否驗(yàn)證通過(guò)
args.IsValid
=
($(
"
#chkCar input:checked
"
).length
>=
3
);
}
</
script
>
</
head
>
最終顯示效果:
ASP.NET jQuery 食譜15 (通過(guò)控件CustomValidator驗(yàn)證CheckBoxList)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元