您的位置:首页 > Web前端 > JavaScript

javascript 一些小知识点

2014-05-10 21:48 225 查看
//动态创建下拉菜单

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<script>

function selected(){

var con=[["选择城市"],["海淀","朝阳","丰台"],["佳木斯","哈尔滨"],["长春","四平","榆树"]];

var se=document.getElementById("seid");

var index=se.selectedIndex;//得到当前选择下拉菜单内容的索引。

// alert(index);

var citys=con[index];

var tg=document.getElementById("tag");

//alert(tg.name);

tg.options.length=0;//清空选择下拉菜单

for(var x=0;x<citys.length;x++){

var op=document.createElement("option");//创建节点

op.innerText=citys[x];//生成下拉菜单内容

tg.appendChild(op);//添加到select节点中

}

}

</script>

</head>

<body>

<select id="seid" onchange="selected()">

<option>选择城市</option>

<option>北京市</option>

<option>黑龙江省</option>

<option>吉林省</option>

</select>

<select name="tagname" id="tag">

<option>选择城市</option>

</select>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: