<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>11111111111111111<a href="javascript:del(1);">del</a> <br><li id="2">2222222222222222<a href="javascript:del(2)%20;">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);%20">del</a> </li> <br><br> </ul> <br><select name="car_type" id="car_type" onchange="add_car(this);"> <br>請選擇選項> <br>11111選項> <br>22222選項> <br>33333選項> <br>44444選項> <br>選擇> <br><input type="text" id="ul_value" onclick="getulvalue();"> <br> <br><br>函數$$(id){ <br>var obj=document.getElementById(id); <br>回傳物件;<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.lengthvar flag =真; <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><br>if(ul_obj[i]. id==car_id){ <br>alert("已經新增! "); <br>標誌=假; <br>} <br>} <br><br>if(flag){ <br>add(car_id,txt); <br>} <br>} <br> <br>}else{ <br>alert("只允許加入三個值!"); <br>回傳; <br>} <br>} <br><br>function getulvalue(){ <br>if ($$('ul').childNodes.length==0){ <br>alert("請選擇相關內容!」); <br>返回; <br>}其他{ <br>var txt="" ; <br>for(var i=0;itxt =$$('ul').childNodes[i].id "," ; <br>} <br>$$("ul_value").value=txt; <br>} <br><br>} <br> <br></ul_obj.length></select> </div>