700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > js 动态生成下拉列表 下拉列表级联

js 动态生成下拉列表 下拉列表级联

时间:2021-06-30 21:48:36

相关推荐

js 动态生成下拉列表  下拉列表级联

简单的动态生成下拉列表 并且 带有级联操作

根据父级节点的值来组织子级下拉列表的值

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script language="javascript">function changeF(fatherValue){if(fatherValue!=null){var s2 = document.getElementById('id2');//s2.length=1;s2.length = 1;//保留下拉列表的第一条,如果将所有的都清楚了,则值等于0即可for(var i=0;i<3;i++){//alert(i);var v = document.createElement('option');v.setAttribute('value', i);var inner = document.createTextNode("我的值是_"+i+"_fatherValue="+fatherValue);v.appendChild(inner);s2.appendChild(v);}}}</script></head><body>父级下拉列表:<select id="id1" name="id1" οnchange="changeF(this.value);"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>子级下拉列表:<select id="id2" name="id2" οnchange="javascript:alert(this.value);"><option value="-1">ok</option></select></body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。