<div class="htmlarea"> <textarea id="runcode13505"> <title>123123</title> <form> <input type="input" id="aa" value="" readonly> <input type="hidden" id="bb" value=""> <input type="hidden" id="cc" value=""> <select style="width: 135px;" id="select" onchange="change(this);creatOptgroup(this);"> <option value=""> </option>카테고리 추가<option value="1"> </option>선물<option value="2"> </option>십이지 별자리<option value="3"> </option>12궁<option value="4"> </option>조디악 2</select> <input type="button" id="del" value="删除分类" onclick="clearOption(document.getElementById('select'));"> </form> </textarea> <br><input onclick="runEx('runcode13505')" type="button" value="运行代码"><input onclick="doCopy('runcode13505')" type="button" value="复制代码"> <input onclick="doSave(runcode13505)" type="button" value="保存代码"> <a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">[Ctrl A 모두 선택 참고: </a>외부 J를 도입해야 하는 경우 실행하려면 새로 고쳐야 합니다 </div>]<script type="text/javascript" language="javascript"> function change(obj){ clearOption(obj); for(var i=0; i<obj.options.length;i++){ if(obj.options[i].value == obj.value){ if(obj.options[i].value != ""){ document.getElementById("aa").value = obj.options[i].text; document.getElementById("bb").value = obj.options[i].value; document.getElementById("cc").value = i; obj.options[0].selected = true; break; } } } } function creatOptgroup(obj){ var hiddenValue = document.getElementById("bb").value; for(var i=0; i<obj.options.length;i++){ if(obj.options[i].value == hiddenValue && hiddenValue != ""){ var group = document.createElement("OPTGROUP"); group.label = obj.options[i].text; obj.insertBefore(group,obj.options(i)); obj.removeChild(obj.options[i]); } } } function clearOption(obj){ if(document.getElementById("bb").value != ""){ var v = document.getElementById("bb").value; var t = document.getElementsByTagName("OPTGROUP")[0].label; var tmpIndex = document.getElementById("cc").value; var o = new Option(t,v,false,false); obj.insertBefore(o,document.getElementsByTagName("OPTGROUP")[0]); obj.options[tmpIndex].text = t; obj.removeChild(document.getElementsByTagName("OPTGROUP")[0]); } document.getElementById("aa").value = ""; document.getElementById("bb").value = ""; document.getElementById("cc").value = ""; } </script>