怎样在客户端得到页面上的dropdownlist当前选中的项目的文字?

马鸣风萧萧 2004-04-11 11:04:17
我在asp.net服务器页面上放了一个web控件dropdownlist:

<asp:DropDownList id="DropDownList1" runat="server" Width="240px" Height="16px" AutoPostBack="True">
<asp:ListItem Value="2" Selected="True">小王</asp:ListItem>
<asp:ListItem Value="3">小昕</asp:ListItem>
<asp:ListItem Value="1">小张</asp:ListItem>
</asp:DropDownList>

现在想在客户端取得下拉框的当前值--text,而不是value,该如何得到?急!!
<script language="javascript">
function intial()
{
GetDropDownList();
}
function GetDropDownList()
{
var str = document.all.DropDownList1.value ;
alert(str);
}
</script>
...全文
57 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
马鸣风萧萧 2004-04-17
  • 打赏
  • 举报
回复
谢谢大家!
飞一龙 2004-04-12
  • 打赏
  • 举报
回复
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<script language="c#" runat="server">
void Page_Load(){
Response.Write (dropdownlist1.SelectedItem.Text);
}
</script>
<form runat="server">
<asp:DropDownList ID="dropdownlist1" AutoPostBack="true" runat="server">
<asp:ListItem Selected="true">aaa</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>

</asp:DropDownList>

</form>
Tomgus 2004-04-11
  • 打赏
  • 举报
回复
来迟了
document.all('DropDownList1').options[document.all('DropDownList1').selectedIndex].text
veryhappy 2004-04-11
  • 打赏
  • 举报
回复
document.all('DropDownList1').options[document.all('DropDownList1').selectedIndex].text
马鸣风萧萧 2004-04-11
  • 打赏
  • 举报
回复
在服务器端很容易得:
string str = this.DropDownList1.Items[this.DropDownList1.SelectedIndex].Text;
或者:
string str = this.DropDownList1.SelectedItem.Text;
可是在客户端没有相关属性。

怎么得到啊,快急死了!
xuu27 2004-04-11
  • 打赏
  • 举报
回复
webcontroler最终也是转换为html element的。注意这点
xueqs 2004-04-11
  • 打赏
  • 举报
回复
document.all('DropDownList1').options[document.all('DropDownList1').selectedIndex].text

lcy5415 2004-04-11
  • 打赏
  • 举报
回复
首先:

RadioButtonList1.DataTextField="Name

RadioButtonList1.DataValueField="id
RadioButtonList1.DataBind();
Hollower 2004-04-11
  • 打赏
  • 举报
回复
同一楼上的!!

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧