如何在javascript中的警报中显示checkboxlist的选定值 [英] how to display the selected values of checkboxlist in an alert in javascript
本文介绍了如何在javascript中的警报中显示checkboxlist的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在javascript中的警报中显示checkboxlist的选定值
例如:
how to display the selected values of checkboxlist in an alert in javascript
eg:
<asp:CheckBoxList ID="chklist" runat="server" >
<asp:ListItem Text="Apple" Value="Apple">
<asp:ListItem Text="Banana" Value="Banana">
<asp:ListItem Text="Orange" Value="Orange">
如果我们选择任何3项,输出应如下所示
输出:Apple,Banana和Orange
if we select any 3 items the output should be as below
output: Apple , Banana and Orange
推荐答案
aspx页面代码:
aspx page code:
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="Apple" Value="Apple"></asp:ListItem>
<asp:ListItem Text="Banana" Value="Banana"></asp:ListItem>
<asp:ListItem Text="Orange" Value="Orange"></asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
代码落后(aspx.cs):
code behind(aspx.cs):
protected void Button1_Click(object sender, EventArgs e)
{
string abc = "";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
abc += item.Value + ',';
}
}
string test = "you have selected " + abc;
Label labelshow = new Label();
labelshow.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + test + "')</script>";
Page.Controls.Add(labelshow);
}
这就是你要找的东西?希望它有帮助!
is this what you were looking for? Hope it Helps!
这篇关于如何在javascript中的警报中显示checkboxlist的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文