日期:2014-05-19  浏览次数:20423 次

如何在javascrip中取 asp.net中downlist下拉框这个对象,及他所选中的值
如何在javascrip中取   asp.net中downlist下拉框这个对象,及他所选中的值

------解决方案--------------------
控件:
var dl= document.getelementbyid( " <%=downlist1.ClientID%> ");
值:
dl.value
------解决方案--------------------
<head runat= "server ">
<title> 无标题页 </title>
<script language= "javascript ">
function getSex()
{
var v = document.getElementById( "DropDownList1 ").options[document.getElementById( "DropDownList1 ").selectedIndex];
alert(v.value + v.text); //v.value为值,v.text为文本
}
</script>
</head>
<body onload= "getSex(); ">
<form id= "form1 " runat= "server ">
<div>
<asp:DropDownList ID= "DropDownList1 " runat= "server ">
<asp:ListItem Value= "1 "> 男 </asp:ListItem>
<asp:ListItem Value= "0 "> 女 </asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
------解决方案--------------------
document.getElementById()
注意大小写不能错
------解决方案--------------------
ls说的对,要区分大小写,刚才没注意

控件:
var dl= document.getElementById( " <%=downlist1.ClientID%> ");
值:
dl.value

------解决方案--------------------
var dd= document.getElementById ( "DropDownList1 ");
alert(dd.options[dd.selectedIndex].value);
测试没问题.
------解决方案--------------------
http://blog.csdn.net/zfmsa/archive/2007/03/13/1528010.aspx
------解决方案--------------------
ma(风筝) :如果使用了母版页,或者作为一个子控件,那样就不行了,呵呵。