一段Javascript代码(转)

本文介绍了一种使用JavaScript动态生成HTML下拉菜单的方法。通过分析提供的JavaScript代码,可以了解到如何根据不同的选项值动态创建<select>元素及其<option>子元素。此方法适用于需要根据用户选择或后台数据实时更新下拉菜单选项的场景。

<script language=javascript>
function OpenDocument(iCategoryID)
{
var a=new Date()
//alert(iCategoryID);
var obj = document.getElementById(iCategoryID);
if(obj.value != null)
{

var ds=obj.value;
if(1==1)
{
var temp=new Array();
temp[0]='<select name="lbxleft">'
for(var i=0;i<10000;i++)
{
var name = i;
var id = i;
temp[temp.length]="<option value='"+id+"'>"+name+"</option>"
/*temp[temp.length]=id
temp[temp.length]="'>"
temp[temp.length]=name
temp[temp.length]="</option>"
*/
}
temp[temp.length]="</select>"
document.all("lbxleft").outerHTML=temp.join("");
}
else
{}
}
document.getElementById("div1").innerHTML=new Date()-a
}
</script>
<select name="aaa" onchange=OpenDocument(this.name)>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
</select>
<select name="lbxleft"></select>

<div id="div1"></div>

转载于:https://www.cnblogs.com/lingxzg/archive/2007/06/26/795972.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值