怎么用js来控制dropdownlist

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么用js来控制dropdownlist相关的知识,希望对你有一定的参考价值。

比如有个dropdownlist第一项是“请选择,后面是其他内容,我选了其他内容,然后点一个按钮调用js使他变成“请选择”

参考技术A function onc()

form1.DropDownList1.value="请选择";

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>请选择</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem Selected="True"></asp:ListItem>
</asp:DropDownList>
<input id="Button1" type="button" value="button" onclick="onc()" /></div>本回答被提问者采纳
参考技术B function
onc()

form1.DropDownList1.value="请选择";

<asp:DropDownList
ID="DropDownList1"
runat="server">
<asp:ListItem>请选择</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem
Selected="True"></asp:ListItem>
</asp:DropDownList>
<input
id="Button1"
type="button"
value="button"
onclick="onc()"
/></div>

js获取和设置dropdownlist的选定项

如题!js获取dropdownlist服务器控件的选定项(asp.net),比如一个dropdownlist的ID=“DllList”,我用document.getElementById("DllList").value或者document.getElementById("DllList").selectIndex类似的方法都获取不到,请求高人指点?

参考技术A 你是要获取下拉框选定项的text值吧,那应该用
document.getElementById("DllList").options[document.getElementById("DllList").selectedIndex].text
参考技术B 要用

document.getElementById('<%=DllList.ClientID%>').value本回答被提问者采纳

以上是关于怎么用js来控制dropdownlist的主要内容,如果未能解决你的问题,请参考以下文章

怎么用js显示隐藏div

js 怎么用一个按钮控制DIV来回显示和隐藏

JS怎么控制footer一直在页面的底部?JS大神来!

怎么用cookie控制一个IP只执行一次JS代码

前端移动端rem页面怎么写js代码怎么写

使用JS控制图片形状