javascript判斷是否有對(duì)RadioButtonList選項(xiàng)選擇

準(zhǔn)備好RadioButtonList數(shù)據(jù)源:
Cosmetic.vb
Imports Microsoft.VisualBasic
Namespace Insus.NET
Public Class Cosmetic
Private _ID As Integer
Private _Type As String
Private _Name As String
Private _Weight As Decimal
Private _UM As String
Public Property ID As Integer
Get
Return _ID
End Get
Set(value As Integer)
_ID = value
End Set
End Property
Public Property Type As String
Get
Return _Type
End Get
Set(value As String)
_Type = value
End Set
End Property
Public Property Name As String
Get
Return _Name
End Get
Set(value As String)
_Name = value
End Set
End Property
Public Property Weight As Decimal
Get
Return _Weight
End Get
Set(value As Decimal)
_Weight = value
End Set
End Property
Public Property UM As String
Get
Return _UM
End Get
Set(value As String)
_UM = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(id As Integer, type As String, name As String, weight As Decimal, um As String)
Me._ID = id
Me._Type = type
Me._Name = name
Me._Weight = weight
Me._UM = um
End Sub
Public Function GetData() As List(Of Cosmetic)
Dim o As New List(Of Cosmetic)
Dim c As New Cosmetic(1, "滋潤(rùn)霜", "玉蘭油", 50, "g")
o.Add(c)
Dim c1 As New Cosmetic(2, "滋潤(rùn)霜", "雅詩(shī)蘭黛", 100, "g")
o.Add(c1)
Dim c2 As New Cosmetic(3, "滋潤(rùn)霜", " 蘭蔻", 80, "g")
o.Add(c2)
Dim c3 As New Cosmetic(4, "滋潤(rùn)霜", "歐萊雅", 60, "g")
o.Add(c3)
Dim c4 As New Cosmetic(5, "滋潤(rùn)霜", "芭比波朗", 120, "g")
o.Add(c4)
Return o
End Function
End Class
End Namespace
在aspx放一個(gè)RadioButtonList控件和一個(gè)銨鈕:
化妝品:<asp:RadioButtonList ID="RadioButtonListCosmetic" runat="server" RepeatColumns="10" RepeatDirection="Horizontal"></asp:RadioButtonList>
<br />
<asp:Button ID="Button1" runat="server" Text="Select" />
在aspx.vb中,為RadioButtonList綁定數(shù)據(jù)源,當(dāng)然綁定數(shù)據(jù)源下面的代碼中,還得引用命名空間 Imports Insus.NET
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Data_Binding()
End If
End Sub
Private Sub Data_Binding()
Dim objCosmetic As New Cosmetic()
Me.RadioButtonListCosmetic.DataSource = objCosmetic.GetData()
Me.RadioButtonListCosmetic.DataTextField = "Name"
Me.RadioButtonListCosmetic.DataValueField = "ID"
Me.RadioButtonListCosmetic.DataBind()
End Sub
接下來(lái)是演示開(kāi)始,寫(xiě)Javascript代碼:
View Code
<script type="text/javascript">
function CheckIsSelected() {
var rbl = document.getElementById("<%=RadioButtonListCosmetic.ClientID%>");
var radio = rbl.getElementsByTagName("input");
var isSelect = false;
for (var i = 0; i < radio.length; i++) {
if (radio[i].checked) {
isSelect = true;
break;
}
}
if (!isSelect) {
alert("請(qǐng)選擇一個(gè)選項(xiàng)。");
}
return isSelect;
}
</script>
最后是為銨鈕Button寫(xiě)客戶端事件
<asp:Button ID="Button1" runat="server" Text="Select" OnClientClick="return CheckIsSelected()" />
相關(guān)文章
基于.Net?Core認(rèn)證授權(quán)方案之JwtBearer認(rèn)證
這篇文章介紹了基于.Net?Core認(rèn)證授權(quán)方案之JwtBearer認(rèn)證,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06VS2015 Update2 構(gòu)建 Android 程序問(wèn)題匯總
這篇文章主要介紹了VS2015 Update2 構(gòu)建 Android 程序問(wèn)題匯總的相關(guān)資料,需要的朋友可以參考下2016-07-07ABP框架中導(dǎo)航菜單的使用及JavaScript API獲取菜單的方法
ABP框架是基于ASP.NET的Web開(kāi)發(fā)框架,其中包含基本的菜單項(xiàng)可供調(diào)用,特別是自動(dòng)生成的js API使得能夠在客戶端獲取菜單,這里我們就來(lái)看一下ABP框架中導(dǎo)航菜單的使用及JavaScript API獲取菜單的方法2016-06-06.NET Core利用動(dòng)態(tài)代理實(shí)現(xiàn)AOP(面向切面編程)
用動(dòng)態(tài)代理可以做AOP(面向切面編程),進(jìn)行無(wú)入侵式實(shí)現(xiàn)自己的擴(kuò)展業(yè)務(wù),調(diào)用者和被調(diào)用者之間的解耦,提高代碼的靈活性和可擴(kuò)展性。本文將為大家詳細(xì)介紹實(shí)現(xiàn)的方法,感興趣的可以學(xué)習(xí)一下2022-01-01ASP.NET?MVC開(kāi)發(fā)接入微信公共平臺(tái)
這篇文章主要為大家介紹了微信平臺(tái)開(kāi)發(fā)ASP.NET?MVC接入微信公共平臺(tái)實(shí)現(xiàn)過(guò)程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04在vs2008中使用AJAX開(kāi)發(fā).net 2.0下的Web程序的方法
最近做項(xiàng)目需要用到AJAX,但是工作需要必須使用.net 2.0版本;但發(fā)現(xiàn)如果項(xiàng)目為.net2.0版本則沒(méi)有Ajax(web.config已經(jīng)配置上ajax) ,、工具欄中并不出現(xiàn)Ajax選項(xiàng)卡. 而且新建頁(yè)面也沒(méi)有AJAX頁(yè)面;后來(lái)查了很多資料 發(fā)現(xiàn)了一種解決方法2011-06-06.net core EF Core調(diào)用存儲(chǔ)過(guò)程的方式
這篇文章主要給大家介紹了關(guān)于.net core EF Core調(diào)用存儲(chǔ)過(guò)程的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用.net core EF Core具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05VS2013安裝時(shí)如何避開(kāi)IE10的限制
這篇文章主要介紹了VS2013安裝時(shí)如何避開(kāi)IE10的限制,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06