右边选中的项目没有全部被删除?函数要怎么改进
程序代码:
<html> <head> <script language="javascript"> function selectChange() { var allNumber=document.selectForm.allItem.options.length; for(var i=0;i<allNumber;i++) { document.selectForm.allItem.options[0]=null; } if(document.selectForm.profession.options[document.selectForm.profession.selectedIndex].text=="学生") { document.selectForm.allItem.options[0]=new Option("数学","数学"); document.selectForm.allItem.options[1]=new Option("语文","语文"); document.selectForm.allItem.options[2]=new Option("英语","英语"); document.selectForm.allItem.options[3]=new Option("Java基础","Java基础"); document.selectForm.allItem.options[2]=new Option("JavaScript应用","JavaScript应用"); } else if(document.selectForm.profession.options[document.selectForm.profession.selectedIndex].text=="运动员") { document.selectForm.allItem.options[0]=new Option("足球","足球"); document.selectForm.allItem.options[1]=new Option("篮球","篮球"); document.selectForm.allItem.options[2]=new Option("排球","排球"); document.selectForm.allItem.options[3]=new Option("网球","网球"); document.selectForm.allItem.options[4]=new Option("羽毛球","羽毛球"); document.selectForm.allItem.options[5]=new Option("游泳","游泳"); document.selectForm.allItem.options[6]=new Option("武术","武术"); document.selectForm.allItem.options[7]=new Option("登山","登山"); } } function checkData(selectedItem)/*检测项目是否已被添加*/ { var flag=true; for(var i=0;i<document.selectForm.selectedItem.options.length;i++) { if(document.selectForm.selectedItem.options[i].text==selectedItem.text) { flag=false; break; } } return flag; } function addSelectedItem()/*添加选中*/ { for(var i=0;i<document.selectForm.allItem.options.length;i++) { if(document.selectForm.allItem.options[i].selected) { if(checkData(document.selectForm.allItem.options[i])) { document.selectForm.selectedItem.options[document.selectForm.selectedItem.length]=new Option (document.selectForm.allItem.options[i].text,document.selectForm.allItem.options[i].value); } } } } function QaddAll()/*添加全部*/ { for(var i=0;i<document.selectForm.selectedItem.length;i++) { document.selectForm.selectedItem.options[i]=null; } for(var i=0;i<document.selectForm.allItem.options.length;i++) { document.selectForm.selectedItem.options[i]=new Option(document.selectForm.allItem.options [i].text,document.selectForm.allItem.options[i].value); } } function deleteSelectedItem()/*删除选中*/ { for(var i=0;i<document.selectForm.selectedItem.length;i++) { if(document.selectForm.selectedItem.options[i].selected) { document.selectForm.selectedItem.options[i]=null; } } } function deleteAll()/*删除全部*/ { var number=document.selectForm.selectedItem.options.length; for(var i=0;i<number;i++) { document.selectForm.selectedItem.options[0]=null; } } </script> </head> <body> <form name="selectForm"> <h5><font size="3">Example:select对象的应用</font></h5> <hr> <b><font size="3"> 选择用户类别:</font></b> <select size="1" name="profession" style="border-style:solid; width:150; height:1" onChange="selectChange()"> <option value="学生" selected>学生</option> <option value="运动员">运动员</option> </select> <br><br> <b><font size="3"> 请选择您曾经学过的课程或者参与过的项目:</font></b> <table border="0" width="560" id="table1" height="210"> <tr> <td width="180" rowspan="6" height="204" align="center"> <select size="13" name="allItem" multiple style="width:150;"> <option value="数学">数学</option> <option value="语文">语文</option> <option value="英语">英语</option> <option value="Java基础">Java基础</option> <option value="JavaScript应用">JavaScript应用</option> </select> </td> <td width="200" height="30"> </td> <td width="180" rowspan="6" height="204" align="center"> <select size="13" name="selectedItem" multiple style="width:150;"> </select> </td> </tr> <tr> <td width="200" height="30" align="center"> <input type="button" value="添加选中" name="addSelect" style="width:100; height=:25" onClick="addSelectedItem()"> </td> </tr> <tr> <td width="200" height="30" align="center"> <input type="button" value="添加全部" name="addAll" style="width:100; height=:25" onClick="QaddAll()"> </td> </tr> <tr> <td width="200" height="30" align="center"> <input type="button" value="删除选中" name="delectSelect" style="width:100; height=:25" onClick="deleteSelectedItem()"> </td> </tr> <tr> <td width="200" height="30" align="center"> <input type="button" value="删除全部" name="addAll" style="width:100; height=:25" onClick="deleteAll()"> </td> </tr> <tr> <td width="145" height="37" align="center"> </td> </tr> </table> </form> </body> </html>为什么“删除选中”按钮不尽人意,我选了几个,点“删除选中”,但选中的没有全部被删除?为啥,请指导下函数哪里需要改进。