zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js操作DropDownList大全

JS 操作 大全 DropDownList
2023-06-13 09:14:32 时间

一:js 设置DropDownList选中某项

1.根据Value值设置选中某项 例子如下:

HTML代码:

<asp:DropDownList ID=”ddlFolder” runat=”server” SkinID=”ddlSkin” AutoPostBack=”false” OnSelectedIndexChanged=”ddlFolder_SelectedIndexChanged”><br /><asp:ListItem Value=”0″>选项0</asp:ListItem><br /><asp:ListItem Value=”1″>选项1</asp:ListItem><br /></asp:DropDownList>

JS代码:

document.getElementById(“ddlFolder”).value=“0”;//0为你要选中的项的value

2.根据Text值设置选中某项

var DropDownListCurrencyNew

= document.getElementById(“ddlFolder”);

for(i = 0; i < DropDownListCurrencyNew.options.length; i++) { if(DropDownListCurrencyNew.options[i].text == “选项0”)

{ DropDownListCurrencyNew.options[i].selected = true; } }

二:js读取DropDownList选中项的value和text

Value:

var selValue = document.getElementById(“DropDownList1“).options[document.getElementById(“DropDownList1“).selectedIndex].value;

Text:

var selText = document.getElementById(“DropDownList1“).options[document.getElementById(“DropDownList1“).selectedIndex].text;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/181165.html原文链接:https://javaforall.cn