html5中js添加下拉菜单
2015-12-04 21:13
495 查看
<select id="first" onchange="change()"></select><br/> <ul id="caidan"></ul> <script> var first = document.getElementById('first'); var caidan = document.getElementById("caidan"); function init() { var arr_first = ['请选择您要吃哪种','凉菜', '热菜', '招牌菜','主食','酒水']; // arr_first.push('北京'); var ops = ''; for (var i = 0; i < arr_first.length; i++) { ops = ops + '<option>' + arr_first[i] + '</option>'; } first.innerHTML = ops; }init(); var caidan_arr = [ ['果仁花生', '拍黄瓜', '肉丝拉皮', '海带丝'], ['宫保鸡丁', '清蒸鲈鱼', '油炸小黄鱼'], ['金银馒头', '黄金米饭'], ['水饺','刀削面'], ['十年果粒橙' ,'百年啤酒','千年白酒','万年泔水'] ] function _clear( _select ) { /*if(_select.length>0) { /!*for(var i=_select.length-1 ; i>=0 ; --i) { _select.options.remove(i); }*!/ while(_select.length>0) { _select.options.remove(0); } }*/ _select.innerHTML = ''; } function addli( txt ) { var _li = document.createElement('li'); _li.textContent = txt; caidan.appendChild(_li); } function change() { // alert(first.textContent); _clear(caidan); var index = first.selectedIndex; if(index ==0) { return; } else { for (var i = 0; i < caidan_arr[index - 1].length; i++) { addli(caidan_arr[index - 1][i]); } } } </script>
相关文章推荐
- javascript 如何定义一个多维数组
- Round() 四舍五入 js银行家算法
- Js获取当前时间、日期
- servlet&jsp 各种乱码问题
- js回到顶部,关闭一个模块的方法
- js超链接
- json的使用(js对象表示法)
- ZeroClipboard.js - 兼容所有浏览器的文字复制功能
- Myeclipse中Java的代码全是黑色的了,但jsp代码就有不同颜色显示?
- web前端学习(二) javascript对象和原型继承
- Round() 四舍五入 js银行家算法
- JavaScript学习(5.4):循环
- JavaScript学习(5.3):条件语句
- Jsp中<%page errorPage%>的使用
- js验证身份证号码
- JS 整理的答疑
- js 倒计时
- 【百度地图API·javascriptapi】地图定位、创建自定义图标、获取用户点击位置
- JS练习题②:数组的全排序
- js加入购物车特效