<div class="codetitle"> <span><a style="CURSOR: pointer" data="92773" class="copybut" id="copybut92773" onclick="doCopy('code92773')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code92773"> <br><ul id="ul"> <br><br><li id="1">11111111111111111<a href="javascript:del(1);">del</a> </li> <br><li id="2">22222222222222222<a href="javascript:del(2);">del</a> </li> <br><li id="3">33333333333333333<a href="javascript:del(3);">del</a> </li> <br><li id="4">44444444444444444<a href="javascript:del(4);">del</a> </li> <br><li id="5">55555555555555555<a href="javascript:del(5);">del</a> </li> <br><br> </ul> <br><select name="car_type" id="car_type" onchange="add_car(this);"> <br><option value="">please select</option> <br><option value="car_11">11111</option> <br><option value="car_22">22222</option> <br><option value="car_33">33333</option> <br><option value="car_44">44444</option> <br></select> <br><input type="text" id="ul_value" onclick="getulvalue();" name="ul_value" value=""> <br><script> <br><br>function $$(id){ <BR>var obj=document.getElementById(id); <BR>return obj; <BR>} <br><br>function del(n) { <BR>$$('ul').removeChild($$(n)); <BR>} <br><br>function add(id,txt) { <BR>var ul=$$('ul'); <BR>var li= document.createElement("li"); <BR>var href_a = document.createElement("a"); <BR>href_a.href="javascript:del('"+id+"');"; <BR>href_a.innerHTML ="del"; <BR>li.innerHTML=txt; <BR>li.id=id; <BR>li.appendChild(href_a); <BR>ul.appendChild(li); <BR>} <br><br>function add_car(obj){ <BR>//chk ul childNodes length <BR>if($$('ul').childNodes.length<3){ <BR>var flag=true; <BR>var ul_obj=$$('ul').childNodes; <BR>var car_id=obj.options[obj.selectedIndex].value; <BR>var txt=obj.options[obj.selectedIndex].text; <BR>if(car_id!=null&&car_id!=""){ <br><br>for(var i=0;i<ul_obj.length;i++){ <br><br>if(ul_obj[i].id==car_id){ <BR>alert("已经添加!"); <BR>flag=false; <BR>} <BR>} <br><br>if(flag){ <BR>add(car_id,txt); <BR>} <BR>} <br><br>}else{ <BR>alert("只允许加入三个值!"); <BR>return; <BR>} <BR>} <br><br>function getulvalue(){ <BR>if($$('ul').childNodes.length==0){ <BR>alert("请选择相关内容!"); <BR>return; <BR>}else{ <BR>var txt=""; <BR>for(var i=0;i<$$('ul').childNodes.length;i++){ <BR>txt+=$$('ul').childNodes[i].id+","; <BR>} <BR>$$("ul_value").value=txt; <BR>} <br><br>} <BR></script> <br> </div>