最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

javascript判断是否有对RadioButtonList选项选择

来源:懂视网 责编:小采 时间:2020-11-27 22:42:03
文档

javascript判断是否有对RadioButtonList选项选择

javascript判断是否有对RadioButtonList选项选择:写Javascript来判断是否有对RadioButtonList选项选择,效果如下: 准备好RadioButtonList数据源: Cosmetic.vb 代码如下:Imports Microsoft.VisualBasic Namespace Insus.NET Public Class Cosmetic Private
推荐度:
导读javascript判断是否有对RadioButtonList选项选择:写Javascript来判断是否有对RadioButtonList选项选择,效果如下: 准备好RadioButtonList数据源: Cosmetic.vb 代码如下:Imports Microsoft.VisualBasic Namespace Insus.NET Public Class Cosmetic Private

写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()" />

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

javascript判断是否有对RadioButtonList选项选择

javascript判断是否有对RadioButtonList选项选择:写Javascript来判断是否有对RadioButtonList选项选择,效果如下: 准备好RadioButtonList数据源: Cosmetic.vb 代码如下:Imports Microsoft.VisualBasic Namespace Insus.NET Public Class Cosmetic Private
推荐度:
标签: 判断 js javascript
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top