一:js 设置DropDownList选中某项
1.根据Value值设置选中某项 例子如下:
HTML代码:
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
本文介绍如何使用JavaScript来设置和获取ASP.NET DropDownList控件的选定项。包括根据Value和Text设置选中项的方法,以及如何读取选中项的Value和Text。
584

被折叠的 条评论
为什么被折叠?



