如何进行js动态生成option?如何实现二级连动
1个回答
2015-02-02
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8>
<title>学了又学</title>
<style type="text/css">
</style>
<script type="text/javascript">
onload = function ()
{
for ( var i = 0; i < 2; i++)
{
funny ();
}
var selects = document.querySelectorAll ("select");
selects[0].onchange = function ()
{
selects[1].value = this.value;
}
}
var funny = function ()
{
var select = document.createElement ("select");
for ( var i = 0; i < 3; i++)
{
var opt = document.createElement ("option");
opt.value = i;
opt.innerHTML = i;
select.appendChild (opt);
}
document.body.appendChild (select);
}
</script>
</head>
<body>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询