佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > javascript判斷是否有對(duì)RadioButtonList選項(xiàng)選擇

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

熱門標(biāo)簽:阿里云 服務(wù)器配置 團(tuán)購(gòu)網(wǎng)站 Linux服務(wù)器 銀行業(yè)務(wù) 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 電子圍欄 Mysql連接數(shù)設(shè)置
寫Javascript來判斷是否有對(duì)RadioButtonList選項(xiàng)選擇,效果如下:

準(zhǔn)備好RadioButtonList數(shù)據(jù)源:
Cosmetic.vb
復(fù)制代碼 代碼如下:

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è)銨鈕:
復(fù)制代碼 代碼如下:

化妝品: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
復(fù)制代碼 代碼如下:

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

接下來是演示開始,寫Javascript代碼:
復(fù)制代碼 代碼如下:

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寫客戶端事件
復(fù)制代碼 代碼如下:

asp:Button ID="Button1" runat="server" Text="Select" OnClientClick="return CheckIsSelected()" />
您可能感興趣的文章:
  • RadioButton實(shí)現(xiàn)選擇后可取消選擇

標(biāo)簽:萍鄉(xiāng) 蚌埠 衡水 江蘇 棗莊 廣元 衢州 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《javascript判斷是否有對(duì)RadioButtonList選項(xiàng)選擇》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    迭部县| 德化县| 洪雅县| 凤冈县| 新竹县| 巴里| 吕梁市| 南漳县| 镇雄县| 枝江市| 凤冈县| 满洲里市| 高淳县| 双峰县| 嘉祥县| 荥经县| 手机| 安阳市| 丹阳市| 萨迦县| 九江县| 沙湾县| 拉孜县| 成都市| 汉沽区| 监利县| 万载县| 临泉县| 东辽县| 滦南县| 巴塘县| 怀化市| 凉城县| 元谋县| 武城县| 卢氏县| 乡宁县| 扶风县| 观塘区| 彭水| 横山县|