<asp:DropDownList style="float:left;" ID="DDL_ShowCompanyName" runat="server" OnSelectedIndexChanged="DDL_NewsTName_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList>
怎样用JS把DDL_ShowCompanyName的selectedvalue赋值给下一个DropDownList
<asp:DropDownList ID="DDL_CompanyName" runat="server" Width="155px">
</asp:DropDownList>
AutoPostBack="True">
</asp:DropDownList>
怎样用JS把DDL_ShowCompanyName的selectedvalue赋值给下一个DropDownList
<asp:DropDownList ID="DDL_CompanyName" runat="server" Width="155px">
</asp:DropDownList>
DropDowList render到页面也是个select
document.getElementById("<%=this.DDL_ShowCompanyName%>"); 这样就可以取到这个DropDowList了,然后取options神马的不用说了吧
如果要在客户端做,要拿到id,如果不用模板,则:
var dpl1 = document.getElementById('DDL_ShowCompanyName');
var dpl2 = document.getElementById('DDL_CompanyName').options;for (var i = 0; i < dpl2.length; i++) {
if (dpl2.options[i] === dpl1.options[dpl1.selectedIndex]) {
dpl2.options[i].selected = true;
break;
}
}用jquery,写法较简洁:$('#DDL_CompanyName').val($('#DDL_ShowCompanyName').val());