javascript判断是否有对RadioButtonList选项选择
更新时间:2021年9月22日 10:17 点击:1577
写Javascript来判断是否有对RadioButtonList选项选择,效果如下:
准备好RadioButtonList数据源:
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, "滋润霜", "玉兰油", 50, "g")
o.Add(c)
Dim c1 As New Cosmetic(2, "滋润霜", "雅诗兰黛", 100, "g")
o.Add(c1)
Dim c2 As New Cosmetic(3, "滋润霜", " 兰蔻", 80, "g")
o.Add(c2)
Dim c3 As New Cosmetic(4, "滋润霜", "欧莱雅", 60, "g")
o.Add(c3)
Dim c4 As New Cosmetic(5, "滋润霜", "芭比波朗", 120, "g")
o.Add(c4)
Return o
End Function
End Class
End Namespace
在aspx放一个RadioButtonList控件和一个铵钮:
化妆品:<asp:RadioButtonList ID="RadioButtonListCosmetic" runat="server" RepeatColumns="10" RepeatDirection="Horizontal"></asp:RadioButtonList>
<br />
<asp:Button ID="Button1" runat="server" Text="Select" />
在aspx.vb中,为RadioButtonList绑定数据源,当然绑定数据源下面的代码中,还得引用命名空间 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
接下来是演示开始,写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("请选择一个选项。");
}
return isSelect;
}
</script>
最后是为铵钮Button写客户端事件
<asp:Button ID="Button1" runat="server" Text="Select" OnClientClick="return CheckIsSelected()" />
准备好RadioButtonList数据源:
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, "滋润霜", "玉兰油", 50, "g")
o.Add(c)
Dim c1 As New Cosmetic(2, "滋润霜", "雅诗兰黛", 100, "g")
o.Add(c1)
Dim c2 As New Cosmetic(3, "滋润霜", " 兰蔻", 80, "g")
o.Add(c2)
Dim c3 As New Cosmetic(4, "滋润霜", "欧莱雅", 60, "g")
o.Add(c3)
Dim c4 As New Cosmetic(5, "滋润霜", "芭比波朗", 120, "g")
o.Add(c4)
Return o
End Function
End Class
End Namespace
在aspx放一个RadioButtonList控件和一个铵钮:
复制代码 代码如下:
化妆品:<asp:RadioButtonList ID="RadioButtonListCosmetic" runat="server" RepeatColumns="10" RepeatDirection="Horizontal"></asp:RadioButtonList>
<br />
<asp:Button ID="Button1" runat="server" Text="Select" />
在aspx.vb中,为RadioButtonList绑定数据源,当然绑定数据源下面的代码中,还得引用命名空间 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
接下来是演示开始,写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("请选择一个选项。");
}
return isSelect;
}
</script>
最后是为铵钮Button写客户端事件
复制代码 代码如下:
<asp:Button ID="Button1" runat="server" Text="Select" OnClientClick="return CheckIsSelected()" />
相关文章
Vue初始化中的选项合并之initInternalComponent详解
这篇文章主要介绍了Vue初始化中的选项合并之initInternalComponent的相关知识,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-06-11Vue.js 带下拉选项的输入框(Textbox with Dropdown)组件
这篇文章主要介绍了Vue.js 带下拉选项的输入框(Textbox with Dropdown)组件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-04-17- 经常需要开发一下小工具,之前都是自己解析命令行参数,接触过动态语言社区以后,发现命令行解析有特定的模式和框架可以利用,本文介绍一个.NET 平台的类库CommandLineParser...2021-09-22
- 这篇文章主要介绍了Vue实例的选项有哪些,文中讲解非常细致,代码帮助大家更好的学习,感兴趣的朋友可以了解下...2020-06-10
ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法
这三个控件都有一个Items集合,可以用 RepeatLayout 和 RepeatDirection 属性来控制列表的呈现形式...2021-09-22ASP.NET中RadioButtonList绑定后台数据后触发点击事件
这篇文章主要介绍了ASP.NET中RadioButtonList绑定后台数据后触发点击事件的相关资料,感兴趣的小伙伴们可以参考一下...2021-09-22- 这篇文章主要介绍了.NET Core系列之MemoryCache 缓存选项,详细的介绍一下 MSCache 中的 Options,由此来介绍一些 MSCache 中的内部机制,感兴趣的小伙伴们可以参考一下...2021-09-22
如何为CheckBoxList和RadioButtonList添加滚动条
这篇文章主要介绍了为CheckBoxList和RadioButtonList添加滚动条的方法,感兴趣的小伙伴们可以参考一下...2021-09-22- 这篇文章主要为大家详细介绍了ASP.NET控件之RadioButtonList的使用方法,感兴趣的小伙伴们可以参考一下...2021-09-22
- 因产品需求和UI样式调整,本文主要实现elementUI下拉选项加多选框的示例代码,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-10-17
RadioButtonList绑定图片及泛型Dictionary应用
读取站点某一目录的图片,需要掌握LINQ与泛型Dictionary<TKey,TValue>的使用,本文将介绍RadioButtonList绑定图片的实现,感兴趣的朋友可以了解下,或许对你有所帮助...2021-09-22实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上
一直想实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上。此功能就是当鼠标经过时RadioButtonList或CheckBoxList每一个Item时,让Item有特效显示,离开时,恢复原样有演示动画,感兴趣的朋友可以了解下啊...2021-09-22无法识别的属性“type”+IIS没有Asp.net配置选项的解决方法
前天在调试asp.net+sql server环境,点这里下载sql server 2005企业版。在测试一个用asp.net+mssql写的留言本程序的时候,报错,提示无法识别的属性“type”...2016-01-27读取XML并绑定至RadioButtonList实现思路及演示动画
读取XML的文档,可以使用System.Data.DataSet类别中的ReadXml()方法,在aspx网页上拉一个RadioButtonList控件,用来显示XML的数据,接下来,用DataSet去读取刚才写好的获取XML文件的属性,即可完成...2021-09-22javascript判断是否有对RadioButtonList选项选择
写个Javascript来判断是否有对RadioButtonList选项选择,附动画演示,感兴趣的朋友可以了解下,希望对您们有帮助...2021-09-22ASP.NET中 RadioButtonList 单选按钮组控件的使用方法
本文主要简单介绍RadioButtonList控件的常见属性和使用方法,希望对大家有所帮助。...2021-09-22在dropDownList中实现既能输入一个新值又能实现下拉选的代码
在dropDownList中实现既能输入一个新值,又能实现下拉选项,想必很多的朋友已经为此功能按耐不住了吧,接下来与大家分享下如何实现,感兴趣的朋友可以参考下哈...2021-09-22- 针对asp.net页面某些选项进行提示判断,比如当保存一个信息时候,需要对当前信息是否为空进行判断...2021-09-22
asp.net使用jQuery获取RadioButtonList成员选中内容和值示例
这篇文章主要介绍了通过jQuery来获取RadioButtonList成员内容的方法,大家参考使用吧...2021-09-22荣耀50pro开发者选项如何开启?荣耀50pro打开开发者选项的方法
荣耀50pro是前不久发布的新款手机,本文中介绍的是使用这款手机开启开发者选项的方法,有需要的朋友不妨阅读参考下...2021-12-01