日期:2014-05-16 浏览次数:20474 次
function AddOption(BuMen_Id, BuMen_Name) { var BuMen_ID = ""; var BuMen_NAME = ""; $("#BenXiaoZuoZhe_BuMen_0").empty(); var html = ""; for (var i = 0; i < BuMen_Id.length; i++) { BuMen_ID = BuMen_Id[i].substring(1, (BuMen_Id[i].length - 1)); BuMen_NAME = BuMen_Name[i].substring(1, (BuMen_Name[i].length - 1)); html += "<option value=\"" + BuMen_ID + "\">" + BuMen_NAME + "</option>"; } $(html).appendTo("#BenXiaoZuoZhe_BuMen_0"); alert(html); }
<td style="text-align: center"> <select name="BenXiaoZuoZhe_BuMen_0" runat="server"> </select> </td>
<asp:DropDownList ID="BenXiaoZuoZhe_BuMen_0" runat="server"> </asp:DropDownList>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>jquery 向下拉单添加选项问题</title> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> </head> <body> <table> <tr> <td style="text-align: center"> <select id="BenXiaoZuoZhe_BuMen_0"></select> </td> </tr> </table> <script language="javascript"> function AddOption(BuMen_Id, BuMen_Name) { var BuMen_ID = ""; var BuMen_NAME = ""; $("#BenXiaoZuoZhe_BuMen_0").empty(); var html = ""; for (var i = 0; i < BuMen_Id.length; i++) { BuMen_ID = BuMen_Id[i].substring(0, (BuMen_Id[i].length)); BuMen_NAME = BuMen_Name[i].substring(0, (BuMen_Name[i].length)); html += "<option value=\"" + BuMen_ID + "\">" + BuMen_NAME + "</option>"; } $("#BenXiaoZuoZhe_BuMen_0").append(html); alert(html); } var BuMen_Id = new Array('SD001T0501','SD001T0502','SD001T0503'); var BuMen_Name = new Array('软件工程系','计科系02','计科系03'); window.onload=AddOption(BuMen_Id,BuMen_Name); </script> </body> </html>
------解决方案--------------