0

如何使用 java 脚本设置选择标签的默认选定索引?我的代码运行良好,但我无法确定默认选定值(例如)第一个值。

  var CompanySelect = document.getElementById("ManagingCompaniesSelect");
if (result && result.length > 0) {
    CompanySelect.options[CompanySelect.options.length] = new Option(_seletCompany, -1);

    for (var i = 0; i <= result.length-1; i++)
    { CompanySelect.options[CompanySelect.options.length] = new Option(result[i].ManagingCompanyName, result[i].MangingCompanyGUId); }
}




var txtManagingCompany = '#ManagingCompaniesSelect' + ' option[value=-1]';
$(txtManagingCompany).attr("selected", "selected");
4

1 回答 1

1

您可以使用该selectedIndex物业。

例子

 CompanySelect.selectedIndex = 0;
 // will select the first option by default and so on.. 
于 2013-07-29T09:22:28.197 回答