读书人

当select中内容过剩时使用搜索

发布时间: 2012-11-07 09:56:10 作者: rapoo

当select中内容过多时,使用搜索

当multiple select中内容过多,为满足软件的易用性,就需要能有搜索功能

var temps_options = new Array();//全局变量数组function select_step(){var list1 = document.getElementById("list1");var step_name = document.getElementById("step_name").value;if (step_name != "") {var selected_options = new Array();for (var i = 0; i < list1.options.length; i++) {if (list1.options[i].text.search(step_name) == 0) {selected_options.push(list1.options[i])}}temps_options = document.getElementById("list1").options; //将所搜剩余的options放入此数组alert(temps_options.length);//1list1.options.length = 0;for (var j = 0; j < selected_options.length; j++) {list1.options.add(new Option(selected_options[j].text, selected_options[j].value));}alert(temps_options.length)//2}else{alert(temps_options[0].text);list1.options.length = 0;for(var i=0;i<temps_options.length;i++){list1.options.add(new Option(temps_options[i].text,temps_options[i].value))}}}


读书人网 >Web前端

热点推荐